3

I want to override or update core validation for magento frontend form like as checkout page form address field validation change. https://i.stack.imgur.com/Q8nw2.png

need to change the core validation

0

You must use this:

1) In input or select tag add our validaion with this code

data-validate="{required:true, 'validate-custom-name':true}"

2) Add js validation for “Validate-custom-name”

<script type="text/javascript">
require(['jquery', // jquery Library
    'jquery/ui', // Jquery UI Library
    'jquery/validate', // Jquery Validation Library
    'mage/translate' // Magento text translate (Validation message translte as per language)
], function($) {
    $.validator.addMethod('validate-custom-name', function(value) {
        return (value !== 'test'); // Validation logic here
    }, $.mage.__('Enter Valid name'));
});
</script>
7
  • I need to core validation change. like as phone no validation change..please see update image. please share full answer..thanx a lot. – Magento2 Devloper Feb 21 '17 at 5:04
  • yeah, exactly! you want to change the validation message, like on phone number field, you want to show Phone number is required, then you can use the above mentioned method only.. – Manish Joy Feb 21 '17 at 5:12
  • which file in change?? i need in my custom module. – Magento2 Devloper Feb 21 '17 at 5:13
  • use first code in the file where the element tag is. and use second code wherever you can run a jQuery code (like phtml etc.) but it is highly recommended to use a js file. – Manish Joy Feb 21 '17 at 5:15
  • I know this work for custom form..can you share full code?? webmull.com/magento-2-add-new-custom-form-validation – Magento2 Devloper Feb 21 '17 at 5:49

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.