How do I validate Credit Card and Bank Account numbers?

th3an0maly picture th3an0maly · Oct 6, 2012 · Viewed 20.3k times · Source

I know there have been a lot of discussion related to this topic, e.g. Credit Card validation: can Card Name contain non-ASCII characters?

The reason I wanted to ask this question is because people could find all the information at one place.

What I've found out (Please correct me if/where I'm wrong):

Title - Length - Format

Credit Card Number - MIN 13, MAX 19 - Numeric

Credit Card Name - MAX 26 - Alpha Numeric (Cannot contain dots after Initials?)

Bank Account Number (btw, I'm in India) - MIN 11, MAX 15 - Numeric

Bank Account Name - Sorry, no idea - Alpha Numeric? (again, no idea)

Please provide answers so that this will help people who have to juggle with financial data.

Answer

Sean Vaughn picture Sean Vaughn · Oct 6, 2012

Read this article: link

It's about generating credit card numbers, but it helps figuring out if the card is valid.

These are the rules that links credit card companies to their credit card numbers:

Visa = 4XXX - XXXX - XXXX - XXXX
MasterCard = 5[1-5]XX - XXXX - XXXX - XXXX
Discover = 6011 - XXXX - XXXX - XXXX
Amex = 3[4,7]X - XXXX - XXXX - XXXX
Diners = 3[0,6,8] - XXXX - XXXX - XXXX
Any Bankcard = 5610 - XXXX - XXXX - XXXX
JCB =  [3088|3096|3112|3158|3337|3528] - XXXX - XXXX - XXXX
Enroute = [2014|2149] - XXXX - XXXX - XXX
Switch = [4903|4911|4936|5641|6333|6759|6334|6767] - XXXX - XXXX - XXXX