function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Admin AdministratorAdmin Administrator 

Validation Rule for Phone Numbers Country Code, Area Code and Number

I'm trying to create a validation rule for our phone numbers. Every number has 3 parts:

Country Code (numerical, 2 digit starts with '+') --> +49
Area Code (numerical, min. 2 digit, max 5 digits, cannot start with 0) --> 42; 421; 4218; 42189
Number (numerical, no digit limit, cannot start with 0)

Examples:

+49 123 1234567

Thanks for help.
KaranrajKaranraj
Try the below regex ecpression for your validation
NOT(REGEX( Phone , "[+][0-9]{2}[' '][1-9]{2}[' '][1-9]*?"))

 
Admin AdministratorAdmin Administrator
Hi Karanraj,

Country Code perfect. Number, too. But how is with Area Code? Area Code is not between 2-4. How can I figure min. 2 digit, max 5 digits?

Thanks for your help.

BR
Ehsan
KaranrajKaranraj
Eshan - Try the below updated regex function
NOT(REGEX( Phone , "[+][0-9]{2}[' '][1-9]{2,5}[' '][1-9]*?"))

 
Admin AdministratorAdmin Administrator
Hello Karanraj,

Perfect. Thanks a lot.

BR
Ehsan
Admin AdministratorAdmin Administrator
@karanraj,

so I tested it in the Live org. I got following result:
Country Code (numerical, 2 digit starts with '+') --> +49 = "[+][0-9]{2}[' ']  CORRECT
Area Code (numerical, min. 2 digit, max 5 digits, cannot start with 0) --> 42; 421; 4218; 42189 = [1-9]{2}[' ']  THIS IS NOT CORRECT, because the 0 ist forbidden. So I can't have a Area code like: 4021 (0 is forbidden)
Number (numerical, no digit limit, cannot start with 0) = [1-9]*?")) IS ALSO INCORRECT, because 0 is forbidden.

Have a another IDEA?

br
Ehsan
Carlos Alberto Villarreal RomoCarlos Alberto Villarreal Romo
@karanraj ,

Can you help with the formula that could allow only in these two formats:
(12) 34567890
(123) 4567890
consider only ten digits, the () and the space after "(" so the formula includes "(##) ########" or "(###) #######"
Malika Pathak 9Malika Pathak 9
Hi there,

find the below solution
For Validation Rule you can refer to below Link:-
https://blog.bessereau.eu/assets/pdfs/salesforce_useful_validation_formulas.pdf

If you find this helpful mark it as the best answer