Carry out the following steps to create a validation rule to validate US zip codes that are well-formed on an account record:
- Click on the Setup gear icon in the top right-hand corner of the main Home page, as shown in the following screenshot:
- Click on Setup, as shown in the following screenshot:
- Navigate to the Account Validations Rule setup page by clicking the following: Objects and Fields | Object Manager | Account | Validation Rules.
Locate the Validation Rules section on the right of the page.
- Click on New.
You will be presented with the Account Validation Rule Edit page.
- Type Valid US Zip Code in the Field Label textbox.
Upon clicking out of the textbox, the name changes to Valid_US_Zip_Code.
- Leave the Active checkbox set.
- Optionally, enter details in the Description field.
Locate the Error Condition Formula section positioned lower down on the page.
- Paste in, or enter, the following code:
AND(NOT( REGEX( BillingPostalCode, "\d{5}(-\d{4})?" ) ), OR(UPPER( BillingCountry ) = "US", UPPER( BillingCountry ) = "USA", UPPER( BillingCountry ) = "U.S.A.", UPPER( BillingCountry ) = "U.S.", UPPER( BillingCountry ) = "UNITED STATES" ) )
- In the Error Message section, enter the text: Please enter a valid US Zip code of the format: five digits as NNNNN or Zip + 4 as in NNNNN-NNNN.
- For the Error Location option, select Field.
You will be presented with the Field selection pick list.
- Select the field, Billing Zip/PostalCode.
- Finally, click on Save, as shown in the following screenshot: