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
JaanuJaanu 

Custom Phone field validation and auto Format ?

I have defined a custom phone field (Type is Phone). When user enters 1234567890, it should be validated - Numeric, Should be 10 digits only, if the validation is ok, when we press enter, it should be formatted as (123) 456-7890. How this can be done please ? 

 
Best Answer chosen by Jaanu
NagendraNagendra (Salesforce Developers) 
Hi Jaanu,

There's a great example in the Useful Validation Rules guide that you can copy (page 15) 
US Phone Number Has Ten Digits Field Value Validates that the Phone number is in (999) 999-9999 format. This works by using the REGEX function to check that the number has ten digits in the (999) 999-9999 format.

Description: 
NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}"))
Formula: Error Message: US phone numbers should be in this format: (999) 999-9999.

Error Location: Phone

Hope this helps.

Kindly mark this as solved if the reply was helpful so that it gets removed from the unanswered queue which results in helping others who are facing a similar issue.

Thanks,
Nagendra

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Jaanu,

There's a great example in the Useful Validation Rules guide that you can copy (page 15) 
US Phone Number Has Ten Digits Field Value Validates that the Phone number is in (999) 999-9999 format. This works by using the REGEX function to check that the number has ten digits in the (999) 999-9999 format.

Description: 
NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}"))
Formula: Error Message: US phone numbers should be in this format: (999) 999-9999.

Error Location: Phone

Hope this helps.

Kindly mark this as solved if the reply was helpful so that it gets removed from the unanswered queue which results in helping others who are facing a similar issue.

Thanks,
Nagendra
This was selected as the best answer
Raj VakatiRaj Vakati
If my understanding is correct, your requirement is not only validation but formatting phone on tab out 

If you wanted to do just formatting along with validation rule , you need to override the custom component or page to do this .. 
Remove the standard filed from the layout and add the page or component ( You can perform validation on the page or component )
 
JaanuJaanu
Yes, not only I have to validate the phone number and also format the USA phone number to (123) 456-7890. Could you please give me the code for this. Thanks.
JaanuJaanu
pls let me know...
Supriya Kakade 15Supriya Kakade 15
Nagendra's best answer it works for US format no.
Description: 
NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}"))