2

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.

  • Hi @Prashant , didd you found the solution – Jaisa Jul 12 '18 at 4:47
  • @sri as per given answer i have override rules js file. add your custom validation to override js file – Prashant Valanda Jul 12 '18 at 15:47
3

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.

  • great, it works! Haven't you found another way without override rules.js? – LucScu Aug 6 '18 at 10:20
  • There is mixin concept but that is not working in my case. Please try with mixin – Prashant Valanda Aug 7 '18 at 6:25
  • yes, i could try to override rules.js, thx very much – LucScu Aug 7 '18 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.