Magento 2 – How to Extend rules.js to Add Custom Validation Rules

magento2validation

How to extend rules.js to add custom validation rules?

Best Answer

you have to set rules.js inside your theme.

First create folder inside your theme Magento_Ui if its already exist then skip it.

keep file into below location from core module.

app/code/Package/themename/Magento_Ui/web/js/lib/validation/rules.js

Remove var folder. Remove pub/static folder contents and run deploy command,

php bin/magento setup:static-content:deploy