There are two factors to consider when deciding how to handle the problem of a work sample: sample size and population characteristics. Sample size is determined by a formula based on the power of the sample or its ability to represent the population with a predictable margin of error.
The resulting complexity makes card type detection code difficult to write, read, and maintain. As an example of this complexity, consider this JavaScript regular expression used to detect Discover card numbers starting with 6011, 622126-622925, 644-649, and 65:
All Visa credit cards start with a 4, MasterCard with a 5, and 6 is dedicated to Discover. The first six digits of your card, including the industry identifier, represent the issuer identification number. This identifies the bank that issued the card. And then, of course, there's your personal account number. This is made up of the seventh digit on -- everything except the last number on your card. The final digit on your credit card is known as the check digit or checksum.. This number is set by something called the Luhn formula, patented by Hans Peter Luhn, an IBM scientist in 1960. It's a formula that uses the numerals in your card's account number to verify that it's valid.