Magento – Magento 2 Custom Validation on Address Book (street[1])

customer-addressform-validationmagento2

For the checkout screen (custom OneStepCheckout plugin) I managed to succesfully add a custom validation rule on the second street input. Now I'd like to do the same for the default Address Book pages, but I can't seem to figure out where.

The custom rule "housenumber" has been added to the \Magento_Ui\web\js\lib\validation\rules.js files within my custom Theme. Preferably I'd like to use this same rule for validation within the edit page (relative path: /customer/address/edit/id/[XXX]/).

Unfortunately most information seems to be about the checkout page, not for the additional forms where addresses can be edited.

Best Answer

I recommend to take a look at this GitHub module

https://github.com/experius/Magento-2-Module-Experius-Address-Lines

 

Mage2 Module Experius AddressLines,

Adds labels to address lines and adds configuration per address line.

Configuration Per Line (Required Entry Yes/No, Label and Validation Classes)

Stores > Configuration > Customers > Customer Configuration > Address Lines

This module also works on the Customer Account Address Edit pages and if you enable the Address to Display on the Customer Registration Page it will also show there.

For more information how to Display the Address on the Customer Registration Page take a look at this blog article I wrote https://codeblog.experius.nl/magento-2-address-fields-customer-registration/

Related Topic