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
MRivasMRivas 

Hi all, I would like to know if there is validation rule that will allow the user to entre a phone number in many formats?

I currently have this formula (below) but it does not allows me to save a phone number with the parenthesis. I want to be able to save the phone with or without the parenthesis. I want the user to be able to save the number in any of these formats: XXXXXXXXXX or XXX-XXX-XXXX or (XXX) XXX-XXXX or (XXX)XXX-XXXX.  All four ways. Is this possible? Witht the formula below I can save the first 2 formats but not the last 2. Thanks

AND(
OR(
ISNEW(),
ISCHANGED(Phone)
),
NOT(ISBLANK(Phone)),
NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}"))
)

Best Answer chosen by MRivas
Alain CabonAlain Cabon
Just by doubling the "\", the regex of regexlib is almost usable directly.

Expression: ^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$

This RegEx requires a US phone number WITH area code. It is written to all users to enter whatever delimiters they want or no delimiters at all (i.e. 111-222-3333, or 111.222.3333, or (111) 222-3333, or 1112223333, etc...).
https://regexlib.com/REDetails.aspx?regexp_id=45

 

All Answers

Alain CabonAlain Cabon
Just by doubling the "\", the regex of regexlib is almost usable directly.

Expression: ^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$

This RegEx requires a US phone number WITH area code. It is written to all users to enter whatever delimiters they want or no delimiters at all (i.e. 111-222-3333, or 111.222.3333, or (111) 222-3333, or 1112223333, etc...).
https://regexlib.com/REDetails.aspx?regexp_id=45

 
This was selected as the best answer
Alain CabonAlain Cabon
US phone:
https://regexlib.com/Search.aspx?k=us+phone&c=-1&m=-1&ps=20 (https://regexlib.com/Search.aspx?k=us+phone&c=-1&m=-1&ps=20)
AnkaiahAnkaiah (Salesforce Developers) 
Hi Mirelis,

Phone field automatic formatting based on User Locale.

Refer the below help article.
https://help.salesforce.com/s/articleView?id=000330422&type=1

If this information helps, Please mark it as best answer.

Thanks!!
 
MRivasMRivas
@Alain 
Is there a way to have many phone fields into one validation rule?? Or salesforce just allows one phone per rule?