# Enforce Address Postcode Validation

**LFS Version requirement:** v11.16 or later

The delivery address form in Limio For Salesforce validates the Postal/Zip Code field value against a Regular Expression from the Custom Metadata Type config.

The validation occurs in the Delivery Contact component, in the Delivery Postal Code field, and depends on the Country being selected.

<figure><img src="https://3950144701-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKxTpA9AeeNYx1ml6UpHj%2Fuploads%2F8n5SHRJeNa35CtGdDdZT%2Fimage.png?alt=media&#x26;token=09a9dafd-87ff-4505-a795-33a60f306c85" alt=""><figcaption></figcaption></figure>

Because the post code validation depends on the country being selected, any given post code is considered invalid as long as country field is not populated.

<figure><img src="https://3950144701-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKxTpA9AeeNYx1ml6UpHj%2Fuploads%2F6sBZrEOuhcJn5k1IAx5Z%2Fimage.png?alt=media&#x26;token=b98928c2-3012-430c-a97d-1cdfb657e550" alt=""><figcaption></figcaption></figure>

NOTE: if the setting is left blank and no regular expression is specified, any post code is considered as valid for the country.

The form supports further customisation for adding a custom validation message specific to each country. In this case the custom message will appear as placeholder to the delivery postal code, to help the user inputting the code in a valid format from the start.

<figure><img src="https://3950144701-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKxTpA9AeeNYx1ml6UpHj%2Fuploads%2FQPjKj4GgsQrLPvX7nRxj%2Fimage.png?alt=media&#x26;token=8145f6d2-fe85-437a-ae4b-0e57d0fec2b0" alt=""><figcaption></figcaption></figure>

If the format used is still invalid against the regex specified, the same validation message will appear as input field error message:

<figure><img src="https://3950144701-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKxTpA9AeeNYx1ml6UpHj%2Fuploads%2F8EFaBvlRixTCAOkaJP8r%2Fimage.png?alt=media&#x26;token=c66d3455-842c-449f-8075-1d444aee29f0" alt=""><figcaption></figcaption></figure>

In order to update the regular expression and the corresponding validation message, follow the instructions below:

1. In the Setup search box, look for the Custom Metadata Types and click 'Manage Records' on the **Region** type.<br>

   <figure><img src="https://3950144701-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKxTpA9AeeNYx1ml6UpHj%2Fuploads%2FIYlqlpc9dLhwXwj1HZia%2Fimage.png?alt=media&#x26;token=48bfe889-118b-4c9a-9d1f-73835f08e25c" alt=""><figcaption></figcaption></figure>
2. Find a region of interest and click 'Edit'. <br>

   <figure><img src="https://3950144701-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKxTpA9AeeNYx1ml6UpHj%2Fuploads%2FleotIWz79udY5wuAtJ5F%2Fimage.png?alt=media&#x26;token=01b9d0a1-68d2-4feb-bb46-1b86ac0eb5cf" alt=""><figcaption></figcaption></figure>
3. Find the **Address Validation** field and populate a **'zip'** property of the object inside with the relevant Regular Expression. <br>

   <figure><img src="https://3950144701-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKxTpA9AeeNYx1ml6UpHj%2Fuploads%2FdW8ka9ABEvbHF0oA4yqH%2Fimage.png?alt=media&#x26;token=211b577f-76e1-4292-9156-3a33666255fa" alt=""><figcaption></figcaption></figure>
4. In the same **Address Validation** filed, add (or edit) the property '**invalid\_code\_msg'** with the relevant message.<br>

   <figure><img src="https://3950144701-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKxTpA9AeeNYx1ml6UpHj%2Fuploads%2FO2wojxLOcfT0MJvj2SXf%2Fimage.png?alt=media&#x26;token=712963eb-c45b-497f-8202-5f38ab2663bc" alt=""><figcaption></figcaption></figure>
5. Save the record.

As an example, the Address Validation can be populated as follows for United Kingdom post codes.

```
{
"posturl": "http://www.royalmail.com/postcode-finder",
"require": "ACZ",
"key": "GB",
"name": "UNITED KINGDOM",
"id": "data/GB",
"locality_name_type": "post_town",
"zipex": "EC1Y 8SY,GIR 0AA,M2 5BQ,M34 4AB,CR0 2YR,DN16 9AA,W1A 4ZZ,EC1A 1HQ,OX14 4PG,BS18 8HF,NR25 7HG,RH6 0NP,BH23 6AA,B6 5BA,SO23 9AP,PO1 3AX,BFPO 61",
"fmt": "%N%n%O%n%A%n%C%n%Z",
"zip": "GIR ?0AA|(?:(?:AB|AL|B|BA|BB|BD|BH|BL|BN|BR|BS|BT|BX|CA|CB|CF|CH|CM|CO|CR|CT|CV|CW|DA|DD|DE|DG|DH|DL|DN|DT|DY|E|EC|EH|EN|EX|FK|FY|G|GL|GY|GU|HA|HD|HG|HP|HR|HS|HU|HX|IG|IM|IP|IV|JE|KA|KT|KW|KY|L|LA|LD|LE|LL|LN|LS|LU|M|ME|MK|ML|N|NE|NG|NN|NP|NR|NW|OL|OX|PA|PE|PH|PL|PO|PR|RG|RH|RM|S|SA|SE|SG|SK|SL|SM|SN|SO|SP|SR|SS|ST|SW|SY|TA|TD|TF|TN|TQ|TR|TS|TW|UB|W|WA|WC|WD|WF|WN|WR|WS|WV|YO|ZE)(?:\\d[\\dA-Z]? ?\\d[ABD-HJLN-UW-Z]{2}))|BFPO ?\\d{1,4}",
"upper": "CZ",
"invalid_code_msg": "For UK use format AB1 CD2"
}
```
