1

In checkout page I try to add validation for postal code.

I already find a list with javascript validation for magento 2 here validation rule and I found this rule "validate-zip-international "but I don't know where to apply this rule. In magento 1 you can add your javascript class in input class on billing.phtml. Does anyone know what it's in Magento 2?

Now by defaul if a type a wrong postal code it only tell me that my code is wrong, and i can pass over this step(like in the next screen-shot)

enter image description here

Dhiren Vasoya
9,70914 gold badges37 silver badges61 bronze badges
asked Jan 5, 2017 at 12:08

1 Answer 1

2

To add validation on the zip field we should overwirte Magento_Checkout/layout/checkout_index_index.xml and add this code :

 <item name="validation" xsi:type="array">
 <item name="zip-range" xsi:type="string">true</item>
</item> 

zip-range for example is a already defined rule in rules.js.

We can overwrite this rule js according to our needs in this location:Theme\Theme\Magento_Ui\web\js\lib\validation\rules.js

answered Aug 16, 2017 at 7:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.