I have 3 phone fields in Salesforce Contact. I am supposed to prevent users from entering characters in the phone field.
I have used the below validation rule
(
Phone != null &&
NOT(
OR(
REGEX(Phone, "[0-9 ]+"),
REGEX(Phone, "\\+[0-9 ]+")
)
)
)
||
(
HomePhone != null &&
NOT(
OR(
REGEX(HomePhone, "[0-9 ]+"),
REGEX(HomePhone, "\\+[0-9 ]+")
)
)
)
||
(
MobilePhone != null &&
NOT(
OR(
REGEX(MobilePhone, "[0-9 ]+"),
REGEX(MobilePhone, "\\+[0-9 ]+")
)
)
)
The issue that I am having is that, when I enter a 10 digit number in mobile field, it is automatically changing it to (XXX) XXX-XXXX format and as a result the validation error is being displayed as it contains characters. Is there any way to stop it.
Best Answer
When you enter phone numbers in standard Phone fields, Salesforce preserves whichever phone number format you enter. Phone fields can accept a maximum of 40 digits in length entered via the Salesforce UI (that can not be done via the API).
Phone field automatic formatting based on User Locale
Phone numbers containing 9 digits
Phone numbers containing 10 digits
Phone numbers containing 11 digits
TIP
Reference:-