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
SV MSV M 

Validate phone number field to accept only numbers

Hi, I would like to validate the phone number field to accept only numbers except zeros.

Acceptable : 9987541452
Not Acceptable : 9010058471

Can someone help me achieve the functionality...

Thanks in advance...
ShirishaShirisha (Salesforce Developers) 
Hi Sai,

Greetings!

You can use the below formual on the validation rule to avoid any other texts and zeros.

OR(NOT(REGEX(MobilePhone,"^[a-zA-Z0-9]*$")),REGEX(MobilePhone,"^[0]*$"))

You can replace the MobilePhone field with the field name of your field.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
AnudeepAnudeep (Salesforce Developers) 
You can use REGEX to perform the check
REGEX(phone, "[1-9]{4}[1-9]{4}[1-9]{2}")
I have taken this from the example listed in this document explaining social security number format
NOT(
OR(
ISBLANK(Social_Security_Number__c),
REGEX( Social_Security_Number__c , "[0-9]{3}-[0-9]{2}-[0-9]{4}")
)
)

If you find this information helpful, please mark this answer as Best. It may help others in the community. Thank You!

Anudeep
 
SV MSV M
Hi Shirisha, 

I've already tried your validation rule but it's not even accepting numbers (1-9)...