Carry out the following steps to create a validation rule to validate UK postcodes 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 UK Postcode in the Field Label textbox.
Upon clicking out of the textbox, the name changes to Valid_UK_Postcode.
- 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( OR(REGEX( BillingPostalCode, "[a-zA-Z]\d\s\d[a-zA-Z]{2}"), REGEX( BillingPostalCode, "[a-zA-Z]\d\d\s\d[a-zA-Z]
{2}"), REGEX( BillingPostalCode, "[a-zA-Z]{2}\d\s\d[a-zA-Z]
{2}"), REGEX( BillingPostalCode, "[a-zA-Z]{2}\d\d\s\d[a-zA-Z]
{2}"), REGEX( BillingPostalCode, "[a-zA-Z]{2}\d[a-zA-Z]\s\d[a
-zA-Z]{2}"), REGEX( BillingPostalCode, "[a-zA-Z]\d[a-zA-Z]\s\d[a-zA-
Z]{2}") ) ), OR( UPPER( BillingCountry ) = "GB", UPPER( BillingCountry ) = "UK", UPPER( BillingCountry ) = "U.K.", UPPER( BillingCountry ) = "UNITED KINGDOM" ) )
- In the Error Message section, enter the text: Please enter a valid UK Post code of the typical format: XXNN NYY.
- For the Error Location option, select Field.
You will be presented with the Field selection pick list.
- Select the field, Billing Zip/Postal Code.
- Finally, click on Save, as shown in the following screenshot: