RegEx for Telephone # with country code included
I need to validate a telephone number in the following format
xx-xxx-xxxxxx
x
can only be a digit and all x开发者_开发技巧
can't be zero.
[1-9]\d-\d{3}-\d{6}
Assuming only the first digit needs to be non-zero.
[1-9]{2}-[1-9]{3}-[1-9]{6}
if none of the digits can be zero.
Anchor with ^
at the beginning and $
at the end as necessary.
x can only be a digit and all x can't be zero.
^(?!0{2})[0-9]{2}-(?!0{3})[0-9]{3}-(?!0{6})[0-9]{6}$
It will not accept all zero country code or all zero telephone number.
精彩评论