Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Telephone Number validation 2

Status
Not open for further replies.

glenmac

Technical User
Jul 3, 2002
947
CA
I was wondering if anyone could help me with a script needed to validate a text field in a form for phone number entry. I think I'll need to use a regular expression to accomplish this. I was thinking of using 3 fields one for area code one for prefix and the last for the number. that way I can limit the first two fields to 3 numbers only and then the last to four numbers. then concatinate the fields fot my form input. Ahe right track or overcomplicating things. All help would be greatly appreciated.
 
Basically, if you go with the three entry method all you will have to verify is that each field is the correct length and numeric. You could still use a regular expression
Code:
([^\d]
jumps to mind) to test for non-numeric characters, and justa plain .length method to doublecheck length.
Then just use the maxlength attribute to limit each text box to 3, 3, and 4.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
This space has nothing in it, it's all ni your imagination
 
Yeah , I guess that's the easiest way to go. It means a lot more code though. I was hoping to find a regex that would do all the verifying for one field. Thanks for your input.
 
Oh, sorry, I thought you had already decided to go with the three fields. If you want to do it in a single field you could do so pretty easily,
There is a regular expression tutorial here ( ) that has as it's final example a telephone number verification. There are also a great deal of regular expressions tutorials for other languages as well that will work similarly in javascript. Also if you go over to the Java forum a friend of mine created a very pretty FAQ on regular expressions in Java.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
This space has nothing in it, it's all ni your imagination
 
Thanks folks for all your help. Tarwin that is a great link (star) BTW I got it working!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top