Ask Search:
Alv von der DeckenAlv von der Decken 

Validation rule for phone number format (regex)

I need your help in order to create a validation rule for telephone number to following format (german phone number system):

"+49", than "-" followed by 3 to 4 digits (0-9), than forced "-" followed by 3 to x digits digits (0-9), possible but not forced "-" followed by 1 to x digits (0-9).

Examples:
+49-123-123
+49-123-1234567
+49-1234-123456789-0
+49-1234-123-123456789

Can anyone create a regex for me?

Thank you very much in advance.
Eric PraudEric Praud
Hi,

try this:
NOT(OR(REGEX( Phone , "[+49]{3}-[0-9]{3}-[0-9]{3}"), 

REGEX( Phone , "[+49]{3}-[0-9]{3}-[0-9]{7}"), 
REGEX( Phone , "[+49]{3}-[0-9]{4}-[0-9]{9}-[0-9]{1}"), 
REGEX( Phone , "[+49]{3}-[0-9]{4}-[0-9]{3}-[0-9]{9}")))

Let me know if this works, thanks
Alv von der DeckenAlv von der Decken
Hello and thanks a lot.

I changed to following and it works just fine:

NOT( OR(
OR( LEN(  Phone  ) = 0,
REGEX(Phone, "[+49]{3}-[1-9]{1}[0-9]{2,3}-[0-9]{3,9}") ,
REGEX(Phone, "[+49]{3}-[1-9]{1}[0-9]{2,3}-[0-9]{3,9}-[0-9]{1,9}"))))