Comparing numbers wrong

I have the following JS which compares credit card number length:

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;
},

I've included the values of console.log() on the 5th & 6th lines. For some reason, it doesn't fail...

update

provider[cardType].validLength is always either '16,13' or '16'

Answers


$.inArray( 16, ['16'] ); //=>-1

Need Your Help

Android runnable on thread called multiple times

android android-arrayadapter asmack android-handler

I am trying to implement MUC with aSmack, but seem to be unable to update the UI with the ArrayAdapter correctly.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.