REGEX function

What is the purpose of REGEX function? By using this function we can build validation rule to enforces proper data format.

Example : Validates Account Billing Zip/Postal Code is in 5 digit format or 9 digit format if billing country is USA.

Steps to create validation rule:

Go to steps -> Build -> Customize -> Account -> Validation Rule and enter required fields and save validation rule.

Error condition formula for this example:

(BillingCountry=="USA")&&NOT(REGEX(BillingPostalCode,"\\d{5}(-\\d{4})?"))

See the below screen for reference.

REGEX

Testing above validation Rule:

To test this validation rule go to account tab and give Billing country = USA and Billig ZIP/Postal code = any number which is not equal to 5 or 9 digit and try to save account record, you will get error message. See below screen for reference.

REGEX