Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 比较数字是错误的_Javascript - Fatal编程技术网

Javascript 比较数字是错误的

Javascript 比较数字是错误的,javascript,Javascript,我有以下比较信用卡号码长度的JS: validate: function () { var ccLength = $('.credit-card input[name="cc_number"]').val().length; var cardType = parseInt($('.credit-card .credit-card-type .selected').attr('rel')); if (!isNaN(cardType)) { console.l

我有以下比较信用卡号码长度的JS:

validate: function () {
    var ccLength = $('.credit-card input[name="cc_number"]').val().length;
    var cardType = parseInt($('.credit-card .credit-card-type .selected').attr('rel'));
    if (!isNaN(cardType)) {
        console.log(ccLength); //11
        console.log(provider[cardType].validLength.split(',')); // ["16", "13"]

        if (ccLength == 0 || (cardType > 0 && (ccLength < parseInt(provider[cardType].validLength)) || (!$.inArray(ccLength, provider[cardType].validLength.split(','))))) {
            triggerNotification('x', 'Your credit card number isn\'t long enough');
            return false;
        } else {
            if ($('.credit-card input[name="cc_cvv"]').val().length < 3) {
                triggerNotification('x', 'You must provide a CCV');
                return false;
            }
        }
    } else {
        triggerNotification('x', 'Credit card type is not recognized or accepted');
        return false;
    }
    return true;
},
我在第5行和第6行中包含了console.log的值。出于某种原因,它不会失败

更新


提供程序[cardType]。有效长度始终为“16,13”或“16”

能否提供正在验证的示例输入?以及您认为它应该失败的原因示例输入包含在控制台后面的注释中。logWhat's ccLength0&&ccLength0周围的额外参数&&ccLength$.inArray( 16, ['16'] ); //=>-1