本文介绍了信用卡的jQuery验证仅限于Visa和Mastercard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jQuery验证插件和其他方法插件.我能够验证抄送字段.我有两个问题.
I am using a jQuery validation plugin and an additional methods plugin. I am able to validate CC field. I have two questions.
- 我如何只限制Visa和Mastercard并显示除这两个以外的消息?
- 如果我输入"0000000000000000",验证插件为什么会认为是有效的卡吗?
- How can I limit only Visa and Mastercard and display a message other than those two?
- If I enter "0000000000000000" why does the validation plugin think it isa valid card?
我使用了建议的caridtcard验证程序,但出现了错误.
I have used suggested caridtcard validator but geting an error.
推荐答案
我创建了一个如下所示的方法.
I have cretaed a method as below.
jQuery.validator.addMethod("vmcardsonly", function(value, element, param) {
if( value.charAt(0) == 4 || value.charAt(0) == 5){
return true;
}else {
return false;
}
}, "Please enter a valid Visa or Master credit card number.");
$('#MyForm').validate({ // initialize the plugin
rules: {
ccNumber1: {
required: true,
number: true,
vmcardsonly: true,
minlength: 16,
maxlength: 16
}
},
submitHandler: function (form) { // for demo
alert('valid form submitted'); // for demo
return false; // for demo
}
});
这篇关于信用卡的jQuery验证仅限于Visa和Mastercard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!