Joe
Joe

Reputation: 1055

Regex Validate French mobile number

I'm trying to validate french mobile numbers: I have already removed all non numeric character and the eventual 00 at beginning, and rules are:

start with 06 or 07 or 09
is 10 digit long:

thus :

/^0(6|7|9)\d{8}$/

but (seems) that if countrycode (33) is present, the leading zero has to be avoided, but at this point I cannot create the right regex, since with number:

33614444444

/^(33|0)?(6|7|9)\d{8}$/

it works, but works also with

614444444

while it should not

can suggest solution?

Upvotes: 0

Views: 4063

Answers (2)

Rajeev Ranjan
Rajeev Ranjan

Reputation: 4096

Why don't you simply use /^(33|0)(6|7|9)\d{8}$/ ?

I do not think you need the quantifier ?.

When you add ? after (33|0). It implies either none of them is present or one of 33 or 0 is present. It would match all the following -

614444444 // none present
0614444444 // 0 present
33614444444 // 33 present

Upvotes: 2

marvel308
marvel308

Reputation: 10458

you can do it using the regex

^(33|0)(6|7|9)\d{8}$

see the regex101 demo

Upvotes: 4

Related Questions