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
Shekhar 13Shekhar 13 

Validation rule for Countries & Phone number code

Hello All,

I have a validation rule where there are 4 countries India, USA, UK & Australia and there phone number must start with +91 or +1 +44 or +61
Please advice .
CharuDuttCharuDutt
Hii Shehar
Try Below Code
IF(ISPICKVAL( Country__c , 'USA') && NOT(ISBLANK( Phone__c )) &&NOT(REGEX(Phone__c ,"[+1]{2}[1-9]{1}[0-9]{9}")),
TRUE,
IF(ISPICKVAL( Country__c ,'India') && NOT(ISBLANK(Phone__c )) && NOT(REGEX(Phone__c ,"[+91]{3}[1-9]{1}[0-9]{9}")),
TRUE,
IF(ISPICKVAL(Country__c,'UK') && NOT(ISBLANK(Phone__c )) && NOT(REGEX(Phone__c ,"[+44]{3}[1-9]{1}[0-9]{9}")),
TRUE,
IF(ISPICKVAL(Country__c,'Australia') && NOT(ISBLANK(Phone__c )) && NOT(REGEX(Phone__c ,"[+61]{3}[1-9]{1}[0-9]{9}")), TRUE,
FALSE)))
Please Mark It As Best Answer If It Helps
Thank You!

 
Suraj Tripathi 47Suraj Tripathi 47
Hi,

You cannot take refrence from the below validation rule on contact.

Please follow the below validation rule in your required code
IF((MailingCountry='US' || MailingCountry='United States') && LEFT(Phone,2)<>'+1', True, IF(MailingCountry='India'&& LEFT(Phone,3)<>'+91', True, IF((MailingCountry='UK' || MailingCountry='United Kingdom') && LEFT(Phone,3)<>'+44', True,
IF((MailingCountry='AUS' || MailingCountry='AUSTRALIA') && LEFT(Phone,3)<>'+61', True, False))))

Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi
ANUTEJANUTEJ (Salesforce Developers) 
Hi Shekhar,

>> https://developer.salesforce.com/forums/?id=9060G0000005d51QAA

The above link has an implementation that is similar to your use case and in it according to the mailing country code they are checking the country code in the phone field.
 
ISPICKVAL(MailingCountryCode , 'US') && LEFT(Phone,2) <> '+1' ||
MailingCountry = 'India' && LEFT(Phone,3) <> '+91' ||
ISPICKVAL(MailingCountryCode , 'UK') && LEFT(Phone,3) <> '+44' ||
MailingCountry = 'Australia' && LEFT(Phone,3) <> '+61' ||
MailingCountry = 'Canada' && LEFT(Phone,2) <> '+1'

Let me know if it helps you and close your query by marking it as the best answer so that it can help others in the future.  

Thanks.
ravi soniravi soni
Hi Shekhar,
try following validation rule.
IF(ISPICKVAL(Country__c, 'India'), AND(Not(ISBLANK(Phone)),LEFT( Phone , 3) <> '+91'),
 IF(ISPICKVAL(Country__c, 'USA'), AND(Not(ISBLANK(Phone)),LEFT( Phone , 2) <> '+1'),
 IF(ISPICKVAL(Country__c, 'UK '), AND(Not(ISBLANK(Phone)),LEFT( Phone , 3) <> '+44'),
 IF(ISPICKVAL(Country__c, 'Australia'), AND(Not(ISBLANK(Phone)),LEFT( Phone , 3) <> '+61'),false)
 )
 )
 )

above validation will be work when user select country and phone number should not be empty and phone number start with +.

I am sure above validation will help you. let me know if it helps you and marking it as best answer.
Thank you
Shekhar 13Shekhar 13
Thank you Veer Soni