Identify if a "Credit card" or "Debit card" by the card number

JibW picture JibW · May 29, 2013 · Viewed 36k times · Source

I can initially do a check to identify if I have a valid Payment Card Number by performing Luhn check algorithm.

But then I need to identify if it is a Credit card or a Debit card to perform the next task accordingly. I understand this depends on the first four characters, but I'm not sure about the exact ranges.

If someone can explain or provide with a link which explains this would be great. Thanks.

Edits...

In both these stackoverflow Links I don't see my question is answered. Therefore this can not be a duplicate for any of these.

In my case it doen't read the card using a card reader and instead using the card number, CVV and exp date to get the payment done(User insert these things).

Also "yes" I can do a check to identify if it is a Visa card, Master Card or an American Express card. But no way to find if its a Credit or a Debit card.(For example if the card is a Visa card then how will I get to know that Visa card is a "credit card" or a "debit card". That's the exact question).

Answer

OldCurmudgeon picture OldCurmudgeon · May 29, 2013

You cannot - unambiguously - tell the difference from just the PAN number. There is no official public database detailing this information and if the banks ever get together to make that happen they will be accused of collusion.

There are some resources online that could be used depending on what country you are in. Barclays offer a PDF document called "CARD IDENTIFICATION AND VALIDATION - Barclaycard" that is applicable to the UK but they will not offer any guarantees as to its accuracy. It is updated approximately quarterly to follow industry changes. You will have to google it as I cannot post a link to a pdf file.

By the way - just doing a LUHN check is not enough because the LUHN check is also used for many other numbers, EAN13 barcodes for example.