

When a modulus operation is applied to the result of step two, the remainder must equal 0 in order for the number to pass the Mod 10 algorithm. The number is reversed and the value of every second digit is doubled, starting with the digit in second place:Īnd the value of every second digit is doubled: We will use the valid credit card number 378282246310005 to demonstrate these steps: There are three steps that the Mod 10 algorithm takes to determine whether or not a credit card number is valid. Before we create that class however, let’s look at how the Mod 10 algorithm works.

whether it passed the Mod 10 algorithm or not).

mastercard: Must have a prefix of 51 to 55, and must be 16 digits in length.A list of these rules for each of the six most popular credit cards is shown below: There are several different types of credit cards that one can use to make a purchase, however they can all be validated using the Mod 10 algorithm.Īs well as passing the Mod 10 algorithm, a credit card number must also pass several different formatting rules. This algorithm processes some simple numerical data validation routines against the number, and the result of this algorithm can be used to determine whether or not a credit card number is valid. What do we actually mean when we say "validate a credit card number"? Quite simply it means that we run a credit card number through a special algorithm known as the Mod 10 algorithm. To implement the class we’ll create in this article, you should have access to an Apache web server running PHP 4.1.0 or later. In this article we’re going to work through the development of a PHP class that stores the details of a credit card and validates its number using the Mod 10 algorithm. Before you actually encrypt your customer’s credit card numbers to a database or forward them to a merchant server, it’s a good idea to implement your own credit card validation routine. Although online payment options such as PayPal have become extremely popular in the last couple of years, the majority of online stores still use some sort of merchant system to accept credit card payments from their Websites.
