Credit card number validating

In other words, if you were creating a new card number and wanted to find the right checksum digit, you'd total up the other digits as shown above except that you wouldn't have the initial digit (2).1 0 4 6 2 2 0 1 8 8 1 4 6 1 0 4 6 2 2 = 58 Using the total (58) you'd take the next highest number that is evenly divisible by ten and subtract the total from this to produce the proper checksum digit (60 - 58 = 2 in this case).It can also help you by eliminating processing on the server for card numbers that are obviously not valid.Here's how the algorithm for the Luhn formula works.Starting with a given credit card number, 1 2 3 4 - 5 6 7 8 - 9 0 1 2 - 3 4 5 2 we reverse the number, removing any non-numeric characters, to create a new string of digits like this (note that the checksum is now the first digit): 2 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 Now we'll look at each individual digit.

This code sample demonstrates the algorithm for validating a credit card number.The Luhn algorithm is primarily used for the validation of credit card numbers.Not only does this provide a catcher for data-entry errors, it also doubles as a weak security tool. That means you can do whatever you want with it — use it in commercial projects, modify it, sell it — as long as you include the copyright notice and licence text.Credit cards on the web sites have become just about as ubiquitous as sign-in forms.

Leave a Reply