乐趣区

关于magento2:Adding-custom-global-javascript-validation

Assuming you add a validation class via the frontend_class let’s say “validate-custom-class” you’ll need to use the following JS to add a custom validation based on a this class:

require([
    'jquery',
    'jquery/ui',
    'jquery/validate',
    'mage/translate'
], function($){ 
    $.validator.addMethod('validate-custom-class', function (value) { 
        // Add your validation logic here
        // Needs to return true if validation pass
        // Or false if validation fails
    }, $.mage.__('Field is not valid'));
});
退出移动版