How to Add Custom Validation Rule to Billing Address Field in Magento 2

billing-addressmagento-2.1validation

I am using magento 2.1.7. I have added vat field to billing address form. I want to add custom field validation. i have added below code.

enter image description here

Added below validation to phtml file

enter image description here

But my custom validation not working. Magento required field validation is working fine. Can anyone help me.

Best Answer

Override rules.js using below code in my custom module

app/code/Test/Custom/view/frontend/requirejs-config.js

var config = {
    "map": {
        "*" : {
            'Magento_Ui/js/lib/validation/rules' : 'Test_Custom/js/validation/rules'
        }
    }
};

created js file at app/code/Test/Custom/view/frontend/web/js/validation/rules.js

Run php bin/magento setup:static-content:deploy command.