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

Phone number Validation in Salesforce

Please help me regarding this validation , 
in the phone field we could enter only 10 digit not more or less than 10 digit and not contain any chanracter and i have created a validation which is as follow but in this there is a problem if we enter a number like 1234567891as then it not showing any error and for every condition it is perfect, please help me.
my validation is:
IF (not(isblank(Phone)),OR(NOT(REGEX(Phone , "\\D*?(\\d\\D*?){10}")), NOT(ISNUMBER(Phone))),NULL)
Jerome LusinchiJerome Lusinchi
Hi Gyani,

In Validation Rule, the result of your criteria need to be true or false.
So do not use if, but AND and OR operators
more like :
AND(not(isblank(Phone)),OR(NOT(REGEX(Phone , "\\D*?(\\d\\D*?){10}")), NOT(ISNUMBER(Phone))))

Check this -
Thanks Jerome and Magulan for your reply but i am getting error when i enter only 10 digit number , i am creating this validation rule on the lead object for the standard Phone field and on the senario when i enter only 10 digit mobile number in the field then in the same i get the same error message , so please help me for this validation rule.
Hey guys,
Finally i got the solution for this situation:

for this first creat a formula field of text data type and the formula field is:

SUBSTITUTE(Phone, "(", ""), ")", ""), " ", ""), "-", "")

and after that create a validation rule on this formula field and validation rule is:

OR(NOT(REGEX(Phone_F__c , "\\D*?(\\d\\D*?){10}")), NOT(ISNUMBER(Phone_F__c)))
pragyanshu kukretipragyanshu kukreti
But Jerome Lusinchi's answer solved my query i simply wanted to test a validation on phone number filed so that it only accepts numeric values of 10 digits no special characters and no alphabets.
Igor PetrovychIgor Petrovych
If you need a more advanced validation, including checking length or if the number is valid at all - you can do that in the trigger handler, and use a ported libphonenumber ( library.