【问题标题】:jQuery-Validation-Engine - Custom funcCall validation causes error when value is emptyjQuery-Validation-Engine - 自定义 funcCall 验证在值为空时导致错误
【发布时间】:2012-11-08 16:28:08
【问题描述】:

我有一个自定义验证函数,可以使用 jQuery-Validation-Engine 验证两个密码字段是否匹配:

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

但是如果没有填充该字段,并且提交了表单,我会得到以下异常:

Uncaught TypeError: Cannot read property 'checkPassordMatch' of undefined 

有什么方法我只能在输入已填充或“必需”首先通过时才运行此验证?

供参考,我的功能如下:

    // 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;
    }
}

欣赏任何想法。

【问题讨论】:

    标签: jquery forms validation jquery-validation-engine


    【解决方案1】:

    不需要这个自定义函数。我可以使用:

    validate[required,equals[password]]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-17
      • 1970-01-01
      • 1970-01-01
      • 2018-01-12
      • 1970-01-01
      • 1970-01-01
      • 2013-02-04
      • 1970-01-01
      相关资源
      最近更新 更多