cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 ZIP Code Validation

Magento 2 ZIP Code Validation

Our company requires an account to be created in order to checkout. Currently, when someone creates an account, there is no validation on the ZIP code field. It seems there is validation for ZIP codes built into either validation.js or rules.js (I've seen both mentioned). How would I get this to apply to the account creation page where users fill in their ZIP codes? Thanks.

3 REPLIES 3

Re: Magento 2 ZIP Code Validation

Hi @radman63,

 

Maybe you can take a look into the Marketplace? https://marketplace.magento.com/catalogsearch/result/?q=address%20validation&idx=m2_cloud_prod_defau...

 

There are several options (I guess)

Re: Magento 2 ZIP Code Validation

There may be something in the marketplace, but I would like to know more about how the validation scripts included with Magento work first, before I consider purchasing a different solution. There seems to be a validation.js file in Magento already. Does anyone know where this is used, and if this file could be modified to add validation rules for a ZIP code?

 

I saw this "somewhere," and was hoping I could use it. It came from a validation.js file, but the file does not look like the validation.js file currently on our site. Maybe it's an example of how someone modified the file I am seeing?

 

"validate-zip-us": [
function (v) {
return $.mage.isEmptyNoTrim(v) || /(^\d{5}$)|(^\d{5}-\d{4}$)/.test(v);

},
'Please enter a valid zip code (Ex: 90602 or 90602-1234).'
],

Re: Magento 2 ZIP Code Validation