I'm trying to implement a Regex that allows me to check if a number is a valid French telephone number.
It must be like this:
0X XX XX XX XX
or:
+33 X XX XX XX XX
Here is what I implemented but it's wrong ...
/^(\+33\s[1-9]{8})|(0[1-9]\s{8})$/
You can use:
^
(?:(?:\+|00)33|0) # Dialing code
\s*[1-9] # First number (from 1 to 9)
(?:[\s.-]*\d{2}){4} # End of the phone number
$
See demo
It allows whitespaces or .
or -
as a separator, or no separator at all
A complex example (the one I'm using):
^(?:(?:\+|00)33[\s.-]{0,3}(?:\(0\)[\s.-]{0,3})?|0)[1-9](?:(?:[\s.-]?\d{2}){4}|\d{2}(?:[\s.-]?\d{3}){2})$
For example it matches each of these lines:
0123456789
01 23 45 67 89
01.23.45.67.89
0123 45.67.89
0033 123-456-789
+33-1.23.45.67.89
+33 - 123 456 789
+33(0) 123 456 789
+33 (0)123 45 67 89
+33 (0)1 2345-6789
+33(0) - 123456789
More:
var phoneExp = /^((\+)33|0|0033)[1-9](\d{2}){4}$/g;
It also takes into account the 0033 scenario.
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