There's a class called "validate-zip" and "validate-zip-international". How does that function know how many digits to validate against? Where do you adjust the settings that affect how many digits to validate against?

This is for Magento 1

  • You can see magento 2 validations at /lib/web/mage/validation.js from your magento root Apr 6 '18 at 9:14
  • 1
    Forgot to mention that this is for Magento 1
    – angelo12
    Apr 6 '18 at 9:22
  • 1
    @angelo12 did my answer not answer your question? Apr 13 '18 at 8:19

You can see all of the validation rules in js/prototype/validation.js

['validate-zip', 'Please enter a valid zip code. For example 90602 or 90602-1234.', function(v) {
     return Validation.get('IsEmpty').test(v) || /(^\d{5}$)|(^\d{5}-\d{4}$)/.test(v);

If we inspect the regex code: /(^\d{5}$)|(^\d{5}-\d{4}$)/
It validates for these formats: 12345 or 12345-1234

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.