Validate few characters of phone number in jquery

mgmhicks
mgmhicks used Ask the Experts™
on
I have a situation where I have a field that I would like to take the following format to be valid.  (999) 255-5555.  However I can have the word 'work' or cell etc... So how can I validate the first few characters (the phone number) but still allow the text after if needed?

thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Using the technique shown herehttp://www.jquerybyexample.net/2012/05/validate-phone-numbers-using-jquery.html?m=1 you then just need to customise the regular expression to what you want. So instead of what they are using

/^[0-9-+]+$/

You could use :

/^(\([0-9]{3}\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}/

Which will allow the formats:

(123) 123-1234
123-123-1234

With anything after them.
Pravin AsarPrincipal Systems Engineer
Top Expert 2005

Commented:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial