Hello,
I am using jQuery Validation and here is the extension that I am using to validate US phone number.
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");
This works great, but what if I only want to validate 2 of the 3 numbers.
For an example, I have
Home Phone: <input name="h" ...>
Work Phone: <input name="w" ...>
Cell Phone: <input name="c" ...>
$('form').validate({
rules: {
h: {phoneUS: true},
w: {phoneUS: true},
c: {phoneUS: true}
}
});