我有单选按钮radioVisa和radioMaster。如果选中其中任何一个,我需要首先检查选择了哪个卡号,然后验证输入的卡号是否有效。我还需要确保只输入数字....我不允许使用任何正则表达式技术...如果检查了radioVisa,它似乎可以工作,但是当我为radioMaster添加代码时,如果检查了它,它就不能工作了……有人能告诉我我哪里做错了吗……
function isValidCardNumber(num, isVisa, isMaster){
var card = new Array();
if (document.getElementById('radioVisa').checked){
card = isVisa;
}
if (num[0] != '4' || num.length != 16 ){
return false;
} else {
return true;
} else if (document.getElementById('radioMaster').checked){
card = isMaster;
}
if (num[0] != '51' || num[0] != '52' || num[0] != '53' ||
num[0] != '54' || num[0] != '55' || num.length != 16 ){
return false;
} else {
return true;
} 发布于 2013-04-27 18:26:58
if (num[0] != '51' || num[0] != '52' || num[0] != '53' ||
num[0] != '54' || num[0] != '55' || num.length != 16 )您不能将numbers.You需要单独指定的所有内容组合在一起。
或
var numbers= ["51", "52", "53", "54",55];
var index = numbers.indexOf(num[0]);如果不存在,则返回-1,否则返回索引
https://stackoverflow.com/questions/16250947
复制相似问题