Magento 2: How to validate Post code field in checkout

Validate Post code

Magento 2 checkout works on knockout js. If there is a requirement to put validation on Post code field we need to add validation using checkout layout file.

Follow the steps to put validation on Post code field on checkout page-

Override Magento_Checkout/layout/checkout_index_index.xml file in custom theme and add below code after line number 207 (below country_id item tag)-


<item name="postcode" xsi:type="array">
<item name="sortOrder" xsi:type="string">75</item>

<item name="component" xsi:type="string">Magento_Ui/js/form/element/post-code</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="string">true</item>
</item>
<item name="validation" xsi:type="array">
<item name="validate-zip-us" xsi:type="string">true</item>
</item>
</item>