+ Start a Discussion
Anuj Joshi 42Anuj Joshi 42 

Validation rule for phone number based on user's iso country code

Hi All,

I want to write a validation rule on phone number custom field. I want to check if the phone number cotains the user's iso country code. For example the user creating or updatin the record has its iso country as INDIA. The validation rule must check if the phone number contains +91. I want to write that for many countries.

Thanks,
Anuj
Jithesh VasudevanJithesh Vasudevan
Hi Anuj,

You can use the below code,
IF( Country !='',NOT(REGEX( Phone , "[+][0-9]{2}[' '][0-9]*{10}")),False)
So a phone number like +91 (850) 644-4201 is valid as per the above formula.  And you can give a proper error mesage which could make the user fill the record more correctly.
Anuj Joshi 42Anuj Joshi 42
Hi Jithesh,

I need to check user's country code and then check. If u are an indian user and u enter +92 and then number, it should throw an error.

Thanks,
Anuj
Jithesh VasudevanJithesh Vasudevan
Is there a limit in the number of countries that you use?
Jithesh VasudevanJithesh Vasudevan
Hi Anuj,

You can use the below formula in that case,

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, False)))

If you have more mailing countries that you use, just take the core formula out of the above one which is,
IF(MailingCountry='<Country Name>' && (LEFT(Phone,3) <> '+<2digits>' ,True,False) and fill it and paste it in the false part of the above formula and do the same logic oif you have many countries to be used.

Take the left pasrt of phone as per the number of digits contains in a country code. For example, for US, it is '+1'. So take LEFT(Phone,2). And for UK(+44) or India(+91), the same is LEFT(Phone,3).

Do let me know if you have any doubts or queries.
sujan chakravarthysujan chakravarthy
hi All,
Phone Number Should start with +91,+01,+44,+61 following numbers,
how to write error condition for this?