简体   繁体   English

jQuery-Validation-Engine-自定义funcCall验证在值为空时导致错误

[英]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: 我有一个自定义验证功能,可以使用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]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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