Regex for french phone numbers

I am trying to implement a regex that allows me to check if a number is a valid French phone number.

It should be like this:

0X XX XX XX XX 

or

 +33 X XX XX XX XX 

Here is what I implemented, but this is wrong ...

 /^(\+33\s[1-9]{8})|(0[1-9]\s{8})$/ 
+5
source share
5 answers

You can use:

 ^ (?:(?:\+|00)33|0) #indicatif \s*[1-9] #first number (from 1 to 9) (?:[\s.-]*\d{2}){4} #End of the phone number $ 

Watch the demo


It allows spaces or . or - as a separator or no separator at all

+8
source

Try the following:

 /^(\+33 |0)[1-9]( \d\d){4}$/ 
+1
source

Divide the regex into two separate parts:

  • prefix, which can be +33 X or 0X

  • the rest of the number ( XX XX XX XX )

Regex will be:

 ^((?:\+33\s|0)[1-9](?:\s\d{2}){4})$ ^ non-capturing group for prefix ^ non-capturing group for number ( ) ^ actual capture group from your original regex 

This allows you to use a space as a separator; if you need something more open, Thomas Ayoub answer is more detailed.

tested in Regex101

Note: According to Thomas's comment, since the regular expression is a complete match using the start and end tokens ( ^$ ), the capture group is redundant. Then you can output it like this:

  ^(?:\+33\s|0)[1-9](?:\s\d{2}){4}$ 

and it should work fine.

+1
source

var phoneExp = / ^ ((+) 33 | 0 | 0033) 1-9 {4} $ / g;

Also takes into account scenario 0033;)

+1
source

A complex example (the one I use):

 ^(?:(?:\+|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 the 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 

Additionally:

+1
source

All Articles