Jump to content

jquery validation quandry


clay1

Recommended Posts

When I click submit nothing happens. I have the problem narrowed down to the zipcode validation.

 

jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
return this.optional(element) || phone_number.length > 9 &&
	phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");

jQuery.validator.addMethod("zipcode", function(zip) {
// matches US ZIP code
// allow either five digits or nine digits with an optional '-' between
zip = zip.replace(/^\s+/, "");
zip = zip.replace(/\s+$/, "");

if(zip.length == 0) {
return true;
}

if(zip.match(/^\d{5}([- ]?\d{4})?$/)) {
return true;
}
return false;
}, "Please specify a valid US ZIP code(5 digits or xxxxx-xxxx format)");

 

 

If I don't enter a zip it tells me to but when I do the form won't post. If I remove that code the form will post but obviously my zipcode field won't be validated. I've tried a few different versions of validating the zip but everytime I try the form won't post.

Link to comment
https://forums.phpfreaks.com/topic/187375-jquery-validation-quandry/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.