Regex | validation error

Posted by MMRUser on Stack Overflow See other posts from Stack Overflow or by MMRUser
Published on 2010-05-20T06:42:27Z Indexed on 2010/05/20 6:50 UTC
Read the original article Hit count: 565

Filed under:
|

I'm trying to validate a USA mobile number, since I'm using pre-built javascript validation library I just replaced this regex validation with the previous one which comes with the validation library.

previous validation regex:

"telephone":{
"regex":"/^[0-9\-\(\)\ ]{10,10}$/",
"alertText":"* Invalid phone number"},

This works like 2126661234 but not in USA standard.

After I changed:

"telephone":{
"regex":"/^[2-9]\d{2}-\d{3}-\d{4}$/",
"alertText":"* Invalid phone number"}, 

Now every entry I get an error even if I enter 212-666-1234 I really don't know what is the wrong, so I'm expecting some help.

© Stack Overflow or respective owner

Related posts about regex

Related posts about JavaScript