• Thursday, July 5, 2018

    [JAVA] How to get credit card/debit card type(i.e. Visa, Master) from card number

    Visa Card, Credit Card, Master Card

    Hello,
    If you want to get card type i.e. Visa, Master, Rupay etc. by card number, here is the code you can use.

    This code uses regex for filtering out card type. You can use this method for getting the card type from card number (without space separation).



    public String getCardType(String mCardNumber) {
            if (mCardNumber.startsWith("4")) {
                return "VISA";
            }else if (mCardNumber.matches("^508[5-9][0-9][0-9]|60698[5-9]|60699[0-9]|607[0-8][0-9][0-9]|6079[0-7][0-9]|60798[0-4]|(?!608000)608[0-4][0-9][0-9]|608500|6521[5-9][0-9]|652[2-9][0-9][0-9]|6530[0-9][0-9]|6531[0-4][0-9]")){
                return "RUPAY";
            } else if (mCardNumber.matches("^((6304)|(6706)|(6771)|(6709))[\\d]+")) {
                return "LASER";
            } else if (mCardNumber.matches("6(?:011|5[0-9]{2})[0-9]{12}[\\d]+")) {
                return "LASER";
            } else if (mCardNumber.matches("(5[06-8]|6\\d)\\d{14}(\\d{2,3})?[\\d]+") || mCardNumber.matches("(5[06-8]|6\\d)[\\d]+") || mCardNumber.matches("((504([435|645|774|775|809|993]))|(60([0206]|[3845]))|(622[018])\\d)[\\d]+")) {
                
                return "MAESTRO";
            } else if (mCardNumber.matches("^5[1-5][\\d]+")) {
                return "MASTER";
            } else if (mCardNumber.matches("^3[47][\\d]+")) {
                return "AMEX";
            } else if (mCardNumber.startsWith("36") || mCardNumber.matches("^30[0-5][\\d]+") || mCardNumber.matches("2(014|149)[\\d]+")) {
                return "DINR";
            } else if (mCardNumber.matches("^35(2[89]|[3-8][0-9])[\\d]+")) {
                return "JCB";
            }
            return "";
        }



    [PHP]How to get credit card/debit card type(i.e. Visa, Master) from card number

    Steve Well

    Author & Editor

    Hi, This is Syed Masoom Rizvi, who is continue exploring the world of programming ,programming and programming... :)

    0 comments:

    Post a Comment