0

我有单选按钮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;
        }    
4

1 回答 1

1
    if (num[0] != '51' || num[0] != '52' ||  num[0] != '53' ||
     num[0] != '54' || num[0] != '55' || num.length != 16 )

You can not combine all those numbers.You need to specify individually.

or

 var numbers= ["51", "52", "53", "54",55];
var index = numbers.indexOf(num[0]);

It will return -1 if that is not exist otherwise return the index

于 2013-04-27T10:26:57.727 回答