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
niharnihar 

Validation Rule for Phone Numbers Country Code and Number

Hi all,

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

Country Code (numerical, 1 digit starts with '+') --> +1

Number (numerical, no digit limit, cannot start with 0)

Examples:

+12019841724

Thanks for help.
Best Answer chosen by nihar
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi Nihar
Try using this formula
AND(
NOT(ISBLANK(Phone)),NOT(REGEX( Phone , "[+][0-9]{1}[1-9]{1}[0-9]*?"))
)

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards

All Answers

Sindhu1234Sindhu1234
Hi Nihar,

Usually, country codes vary some might have 0ne and some will have 2 or 3.
Secondly do you separate country code and phone by - or any space.
The best way is to use the Regex function.

 
Aman PathakAman Pathak
Hi ,

Have you tried using regex , 
form the regex such that it will suit your requirement,  add it into validation rule.

for example :  to allow only +1 1 +12 12 +123 1234
use regex like :
/^(\+?\d{1,3}|\d{1,4})$/

Thanks,
Aman
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi Nihar
Try using this formula
AND(
NOT(ISBLANK(Phone)),NOT(REGEX( Phone , "[+][0-9]{1}[1-9]{1}[0-9]*?"))
)

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards
This was selected as the best answer