Validation Rule on Phone field

 

Validation Rule on Phone field


To create a validation rule on a phone field in Salesforce, you can use a regular expression pattern that matches the desired format of the phone number. Here is an example of a validation rule that ensures that the phone number is in the format (123) 456-7890:

NOT(REGEX(Phone__c, "^\\(\\d{3}\\) \\d{3}-\\d{4}$"))

This rule uses the REGEX function to check if the Phone__c field matches the specified pattern. If it does not match, the NOT function returns true and the validation error will be displayed.

To apply this validation rule, go to the object's page layout in Setup, click on the phone field, and then click on the "Validation Rules" related list. Create a new validation rule and enter the above formula in the formula field.

Note: Replace Phone__c with the actual API name of your phone field.

Post a Comment

0 Comments