Italian phone 10-digit number regex issue

Viewed 10490

I'm trying to use the regex from this site

/^([+]39)?((38[{8,9}|0])|(34[{7-9}|0])|(36[6|8|0])|(33[{3-9}|0])|(32[{8,9}]))([\d]{7})$/

for italian mobile phone numbers but a simple number as 3491234567 results invalid.

(don't care about spaces as i'll trim them)

should pass:
349 1234567
+39 349 1234567
TODO: 0039 349 1234567
TODO: (+39) 349 1234567
TODO: (0039) 349 1234567

regex101 and regexr both pass the validation..what's wrong?

UPDATE:

To clarify: The regex should match any number that starts with either

388/389/380 (38[{8,9}|0])|

or 347/348/349/340 (34[{7-9}|0])|

or 366/368/360 (36[6|8|0])|

or 333/334/335/336/337/338/339/330 (33[{3-9}|0])|

328/329 (32[{8,9}])

plus 7 digits ([\d]{7})

and the +39 at the start optionally ([+]39)?

4 Answers

I found this and i updated with new operators and MVNO prefixes (Iliad, ho.)

^(\((00|\+)39\)|(00|\+)39)?(38[890]|34[4-90]|36[680]|33[13-90]|32[89]|35[01]|37[019])\d{6,7}$

I improved the regex adding the case to handle space between numbers:

^(\((00|\+)39\)|(00|\+)39)?(38[890]|34[4-90]|36[680]|33[13-90]|32[89]|35[01]|37[019])(\s?\d{3}\s?\d{3,4}|\d{6,7})$

so, for example, I can match phone number like this (0039) 349 123 4567 or this 349 123 4567

Following doc:

https://it.qaz.wiki/wiki/Telephone_numbers_in_Italy

A simple regex for MOBILE italian numbers without special chars is:

/^3[0-9]{8,9}$/

it match a string starting with the digit '3' and followed by 8 or 9 digits, ex:

3345678103

you can add then ITALIAN prefix like '+39 ' or '0039 '

/^+39 3[0-9]{8,9}$/ --- match --> +39 3345678103

/^\0039 3[0-9]{8,9}$/ --- match --> 0039 3345678103

Related