JQuery CreditCardvalidation器扩展

我正在使用Jquery Validator我的挑战是当用户更新他们的个人资料信息时。 但不改变他们的CC。

在更新页面中,我只显示4 * * ** * 1111

因此,如果使用以下validation失败:(下面的代码片段)

$("#profile-form").validate({ rules: { ccnum: { required: true, creditcard: true }, exp_year: { ccDate: true}, exp_month: { ccDate: true} } 

但是如果用户输入一个新的CC号码,它就会按照它想要的那样做。

所以我的问题是,如果用户想要更新其他内容并且不接触CC卡,我该怎么办?

有什么想法/建议吗?

如果元素的值发生了变化,我会编写一个调用信用卡validation方法的新规则:

 $.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/