I am trying to create a regex that validates the 2 first characters of an international phone number as the user types it in:
Is valid: +
, 0
, + followed by a number
, 00
, 0032476382763
, +324763
Is not valid: 0 followed by a number different than 0
, ++
, everything that is not in the valid list
So far I have come up with:
/[0]|[00]|[+]|[+\d]]/g
But this validates ++
but not +2
. The problem is that I can't figure out how to validate depending on the number of characters (1 or 2).
I am using that expression in javascript
. Here's the regex I worked on: http://regexr.com/3br5v
My level in regex is not very good, so any help would be very much appreciated.
This seems to do the trick (fixed bug with false positive 01
):
/^([+]|00|0$)(\d*)$/
https://regex101.com/r/qT0dB7/2
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