简体   繁体   中英

jQuery-Validation-Engine - Custom funcCall validation causes error when value is empty

I have a custom validation function to verify that two password fields match using jQuery-Validation-Engine:

<input type="password" class="validate[required,funcCall[checkPassordMatch],maxSize[25]]"...

But if the field is not populated, and the form is submitted, I get the following exception:

Uncaught TypeError: Cannot read property 'checkPassordMatch' of undefined 

Is there any way I can only run this validation only if the input is populated, or if "required" passes first?

For reference, my function is as follows:

    // Validate the passwords match
function checkPassordMatch(field, rules, i, options){
    console.log(field + ' : ' + rules + ' : ' + i  + ' : ' + options )

    if (field.val() != jQuery("#inputPassword").val()) {
        return options.allrules.passwordMatch.alertText;
    }
}

Appreciate any thoughts.

This custom function is not needed. I can use:

validate[required,equals[password]]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM