I searched for phone number validation and ended up with below javascript code
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(/^\(?(\d{3})\)?[-\. ]?(\d{3})[-\. ]?(\d{4})$/);
}, "");
The above code will return true for below formats
123-123-1234 or (123) 123-1234 or 1231231234
Nw I need to add extension for number for eg
123-123-1234 x1234
(123) 123-1234 x1234
1231231234 x1234
I tried with all my experience with regex (much little :) ) but didn't worked :(
Can you change in my regex to validate x1234
Thanks.