jQuery信用卡验证器扩展 [英] JQuery CreditCard validator extend
问题描述
我正在使用Jquery Validator 我的挑战是用户何时更新其个人资料信息.但不更改其CC.
I am using Jquery Validator My challenge is when the user is updating their profile info. but not changing their CC .
在更新页面中,我只显示4 * * ** * 1111
When in the update page i only show 4*****1111
因此,如果使用以下代码,验证将失败:(下面的代码段)
So the validation fails if use: (code snippet below)
$("#profile-form").validate({
rules: {
ccnum: { required: true, creditcard: true },
exp_year: { ccDate: true},
exp_month: { ccDate: true}
}
但是,如果用户输入一个新的抄送号码,它会执行它应该执行的操作.
But if the user enters a new CC number it does what it is suppose to.
所以我的问题是,如果用户要更新其他内容并保持CC卡不变,该怎么办.
So my problem what can i do if the user wants to update something else and leave the CC card un-touched.
有什么想法/建议吗?
推荐答案
如果元素的值已更改,我将编写一条新规则来调用信用卡验证方法:
I would write a new rule that calls the credit card validation method if the element's value has changed:
$.validator.addMethod("creditcard-custom", function (value, element) {
return this.optional(element) ||
element.value === element.defaultValue ||
$.validator.methods.creditcard.call(this, value, element);
}, $.validator.messages.creditcard);
用法:
$("#myform").validate({
rules: {
ccnum: {
required: true,
'creditcard-custom': true
},
exp_year: {
ccDate: true
},
exp_month: {
ccDate: true
}
}
});
示例: http://jsfiddle.net/andrewwhitaker/kqczf/2/
这篇关于jQuery信用卡验证器扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!