Forum Moderators: open

Message Too Old, No Replies

phone no validation

use regular Expression

         

Abhishek Kumar

12:50 pm on Feb 9, 2007 (gmt 0)

10+ Year Member


please help me javascript code validation for Phone No use for regular Expression

Fotiman

3:40 pm on Feb 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you have a specific format the number should be in? For example:

(ddd) ddd-dddd
or
ddd-ddd-dddd
or
1-ddd-ddd-dddd

Where each "d" is a numeric digit. And are there any optional parts? That is could some type either of these:

18005551212
or
1-800-555-1212

DrDoc

7:59 pm on Feb 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Better yet, format your HTML accordingly. For a US phone number, for example:

(<input type="text" size="3" name="phone1">)
<input type="text" size="3" name="phone2">-<input type="text" size="4" name="phone3">

Which would display something like this:

([___]) [___]-[____]

[edited by: DrDoc at 8:00 pm (utc) on Feb. 9, 2007]

LifeinAsia

8:05 pm on Feb 9, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



It will be a lot more complicated if you need phone numbers outside of North America- forget about nice, standardized 10-digit numbers!

carguy84

4:46 am on Feb 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



let the user input it in whatever way they do, strip out everything that isn't a number, check to make sure there are 10 digits, store only the digits.