Credit card numbers are all numeric and have fixed lengths (13 digits for Diners Club, 15 for American Express, and 16 digits for all the others). The card numbers also contain what is called a "check digit" to help ensure that if you transpose digits in yor credit card number that you are not accidentally quoting a number belonging to someone else. This means that only certain number combinations are valid.
If you enter something into the above field then when you select the validate button an alert box will display to tell you whether the number entered could be a valid credit card number. You can apply this validation to your own credit card number fields by calling the following validation routine from where ever in your code you want to perform the validation, just pass the field to be validated (non-numerics in the field will be ignored), the function will return true if the number supplied is the correct length and could be a credit card number or false if it is definitely not a valid card number:
Note that this routine only tests if the number entered is the right length to be a credit card number and contains the correct check digit. Numbers accepted by this code could be valid credit card numbers but may not actually correspond to a card that has been issued, ones rejected by the routine are definitely not valid. To properly validate credit card numbers requires server side processing but this code will help you to reject many invalid numbers before the server side routine needs to be called. Note also that this script handles preliminary validation only and does not contain any code relating to security. You need to have appropriate security measures (including PCI compliance) in place if you are going to ask for people to enter their credit card numbers on your site.
Felgall Pty Ltd accepts no responsibility for the security of credit card numbers entered on web pages that use this preliminary validation script.
This article written by Stephen Chapman, Felgall Pty Ltd.