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:
The maximum length of a credit card number is 19 digits, with the maximum length of the account number field being 12 digits (initial six-digit issuer identifier minus the final digit check number). Each issuer has 1 trillion possible account numbers. The final digit of your credit card number is a check digit, similar to a checksum. The algorithm used to arrive at the correct digit is called the Luhn algorithm, after IBM scientist Peter Luhn. The check digit is used to confirm the initial digits of the card number.