I need a javascript regex for validation of numbers that are phone numbers. The numbers cannot be a single zero or only zeroes.
e.g
0
000
00000-000-(000)
these are not allowed.
But these are allowed:
01-0808-000
10(123)(1234)
11111
The javascript regex I have so far is:
/^[!0]*[0-9-\)\(]+$/
But this does not seem to work.
The rule is the phone number can contain numbers and -
and (
and )
. It can start with a 0 but the phone number cannot be a single 0 or a number of zeroes only with or without the above characters.
Could you point me in the right direction. Thanks in advance.
This regex should work:
^(?=.*?[1-9])[0-9()-]+$
Can try this:
/[0-9-()]*[1-9][0-9-()]*/
Will match any number of allowed chars and digits, but if there is no 1-9 anywhere the middle part won't get matched.
/[0-9-()]*[1-9][0-9-()]*/
Debuggex Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With