Reputation: 27058
I've been looking at many regexp validations for phone numbers but I could not find one that allows only 10 digits and not to start with 0 or 1, obviously only numbers
I found this one
^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$
but is to allowing for what I need.
I am using this expression in javascript and I can use the max 10 digits there.
any ideas?
Upvotes: 1
Views: 3938
Reputation: 23
If you have 3 input boxes for phone number and wanna test the first box, use the same regexp suggested by @m0skit0...
/^[2-9]\d{2}$/.test(phone_field_1.val())
Upvotes: 0
Reputation: 559
Here you see my solution with 10 digits. Important: They don't start with 0 or 1 !!!
^[2-9]\d{9}$
Further explanation:
^ beginning of string
[2-9] matches only digits 2 to 9 (NOT 0 and 1 as I mentioned above)
\d{9} any 9 digits
$ end of string
I hope I could help you!
Upvotes: -2
Reputation: 25874
10 digits, not starting with 0 or 1:
^[2-9]\d{9}$
Quick explanation:
^ start of string
[2-9] matches only digits 2 to 9 (thus excluding 0 and 1 as requested)
\d{9} any 9 digits
$ end of string
Upvotes: 7