hemtros
10/17/2016 - 10:54 PM

Find Card type by card number

Find Card type by card number

function GetCardType(number) {
    var re = new RegExp("^4");
    if (number.match(re) != null)
        return "VISA";

    re = new RegExp("^(34|37)");
    if (number.match(re) != null)
        return "AMEX";

    re = new RegExp("^5[1-5]");
    if (number.match(re) != null)
        return "MC";

    re = new RegExp("^6011");
    if (number.match(re) != null)
        return "DISCOVER";

    return "";
}