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:
Each type of account number hasspecific lengths, which can serve as a secondary method to identify the type of credit card. For example, Visa account numbers are either 13 or 15 digits long. If you see a credit card number that starts with a 4 and contains 13 or 15 digits, you can assume it's a Visa. Mastercard and Discover account numbers contain 16 digits. American Express contains 15 digits, and Diner's Club and Carte Blanche contain 14 digits.