0

I am looking to do some validation inside my jquery script for numbers and email. I am unsure how i can add this to my current script? This is what i have so far:

<script>      
       $("#quote-me").click(function(e){
         e.preventDefault();  
         var pnum = $("#partnum").val();
         var quantity = $("#quant").val();
         var location = $("#locate").val();
         var custemail = $("#email").val();

         var r = $.ajax({

            url : "/support/quote/",
            dataType : "JSON",
            type : "POST",
            data : {
                action : "true",
                pnum : pnum,
                quantity : quantity,
                location : location,
                custemail : custemail
            }
        });
        r.done(function(response){
            if(response.confirm !== undefined) {

                $("#confirmmessage").html(response.confirm);
                $("#confirmmessage").show(); 
                $("#speedquoteform input[type='text']").val("");
             }

        });
         });

         $("#speedquoteform input[type='text']").focusin(function() {
            if($("#confirmmessage").is(":visible")) { 
                $("#confirmmessage").hide(); 
            }

         });

    </script>
Sparky
  • 98,165
  • 25
  • 199
  • 285
ash
  • 93
  • 5
  • 14
  • Validation of email address: http://stackoverflow.com/questions/2855865/jquery-regex-validation-of-e-mail-address – Luke Shaheen Mar 27 '13 at 13:09
  • Validation of phone number: http://stackoverflow.com/questions/9262942/jquery-form-validation-telephone-number – Luke Shaheen Mar 27 '13 at 13:09
  • Are you asking how to do the validation or where to place the code? If the first, what are your conditions? If the second, then the answer is after your call to e.preventDefault() and before you make your r = $.ajax() assignment. – jimcavoli Mar 27 '13 at 13:10
  • This question has absolutely nothing to do with the [tag:jquery-validate] plugin. Edited tags. – Sparky Mar 27 '13 at 14:37

1 Answers1

0

You can use $.isNumeric() to check if a variable is a number:

quantity.isNumeric();  // assuming 'quantity' is what you intend to validate
cmallard
  • 151
  • 6