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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.