Skip to content

Instantly share code, notes, and snippets.

@docto
Forked from Rio517/jquery.validate.phone.js
Created August 23, 2013 01:14
Show Gist options
  • Save docto/6314565 to your computer and use it in GitHub Desktop.
Save docto/6314565 to your computer and use it in GitHub Desktop.
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");
// Source: http://docs.jquery.com/Plugins/Validation/CustomMethods/phoneUS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment