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.
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.
Validation rule above is giving syntax error.
Hi Sahaj,
No issues with the validation rule. I think your facing issues with font. Do not copy paste the formula. Recreate it.
(BillingCountry==”USA”)&&NOT(REGEX(BillingPostalCode ,”\\d{5}(-\\d{4})?”))
its very help full to beginner thank you
The Validation rule is Correct, But its not working for 9-digit Zip code. When I try to save the Account with 9 digit Zip code, why the rule is giving error ?