Magento – How does the zip code validation work

magento-1validation

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

Best Answer

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