REGEX Validation Rules Salesforce
To write validation rules in salesforce, it does support many functions to define the specific type of data only to allow. But sometimes these functions are not suited to write a validation rule that fulfills your requirement. so in that case, we can use REGEX functions.
[REGEX(Text, RegEx_Text)]
Returns TRUE if Text matches the regular expression RegEx_Text. Otherwise, it returns FALSE.
NOTE: Formula fields do NOT support the REGEX function.
Write REGEX function in Validation
Write a simple validation rule to the Account object Phone field. Phone Numbers should be 10 digits only.
Setup --> Object Manager --> Account --> Validation rules--> Create NEW.
add about regex code and save it.
Now open the Account tab --> Create a new account and try to add more than 10 digits and save it. You will get an error message written on validation rule.
For more REGEX function Examples
COMMENTS