How to add a custom Zip Code validation in checkout page Magento 2?

I am going to cover in this post how to customise Magento checkout page zip code validation. In Magento it is very easy to customise zip code validation using regular expressions. 

In default Magento all validations regular expressions defined in below file:


To customise zip code validation on checkout page for a specific country, you can customise as below shared steps:

  1. Create zip_codes.xml file to MM\Training\etc folder, Here I have created my own module(MM_Training). Make sure after creating module it should be enabled.
  2. Add below code to zip_codes.xml

In the given example I have covered SG country, with one pattern. If you require multiple patterns for a single country you can add multiple code nodes with more patterns.

Flush Magento cache and test your added new custom zip code validation on checkout page.

Leave a Reply

Your email address will not be published. Required fields are marked *