How to do it...

Carry out the following steps to create a validation rule to validate US zip codes that are well-formed on an account record:

  1. Click on the Setup gear icon in the top right-hand corner of the main Home page, as shown in the following screenshot:
  1. Click on Setup, as shown in the following screenshot:
  1. 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.

  1. Click on New.

You will be presented with the Account Validation Rule Edit page.

  1. Type Valid US Zip Code in the Field Label textbox.

Upon clicking out of the textbox, the name changes to Valid_US_Zip_Code.

  1. Leave the Active checkbox set.
  2. Optionally, enter details in the Description field.

Locate the Error Condition Formula section positioned lower down on the page.

  1. 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" 
    )  
) 
  1. 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.
  2. For the Error Location option, select Field.

You will be presented with the Field selection pick list.

  1. Select the field, Billing Zip/PostalCode.

 

  1. Finally, click on Save, as shown in the following screenshot:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset