C problems validating a credit card
Starting with the second digit in the string, we double every other number. 2 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 This creates a new string of digits shown here: 2 10 4 6 2 2 0 18 8 14 6 10 4 6 2 2 Finally, we go through this new string and add up each single digit to produce a total.
In other words, for this example, we don't add 2 10 ... instead: 2 1 0 4 6 2 2 0 1 8 8 1 4 6 1 0 4 6 2 2 = 60 You may have noticed that the checksum digit (2) is included in the sum.
When actually processing a transaction, you'd also want to check the customer name, expiration date, etc. The code demonstrated here is really just a first step, meant to help the user by checking for typos or invalid characters.
It can also help you by eliminating processing on the server for card numbers that are obviously not valid.
By performing the same calculations, you can determine if the number matches the checksum digit. Note that if a number passes this test, it does not necessarily mean that it is definitely valid.
Usually, other checks should be made to determine if the card number is acceptable.
If the total was already an even multiple of ten, say 70, the checksum would simply be zero.
For almost all credit cards, the Luhn Formula is used.
This algorithm generates a single digit which is then used as the last digit of the card number. It merely triggers a call to the Java Script function to check the number (you can view the page source to see this for yourself).
They follow whatever coding scheme that particular card company chooses.
The last digit, however, is generated by performing a fixed set of calculations on the other digits.Sending a debt validation letter would help you be sure you're paying the right company for the right debt.