Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are three parts to the validation of the card number:</p> <ol> <li><strong>PATTERN</strong> - does it match an issuers pattern (e.g. VISA/Mastercard/etc.)</li> <li><strong>CHECKSUM</strong> - does it actually check-sum (e.g. not just 13 random numbers after "34" to make it an AMEX card number)</li> <li><strong>REALLY EXISTS</strong> - does it actually have an associated account (you are unlikely to get this without a merchant account)</li> </ol> <h2>Pattern</h2> <ul> <li>MASTERCARD Prefix=51-55, Length=16 (Mod10 checksummed)</li> <li>VISA Prefix=4, Length=13 or 16 (Mod10)</li> <li>AMEX Prefix=34 or 37, Length=15 (Mod10)</li> <li>Diners Club/Carte Prefix=300-305, 36 or 38, Length=14 (Mod10)</li> <li>Discover Prefix=6011,622126-622925,644-649,65, Length=16, (Mod10)</li> <li>etc. (<a href="http://en.wikipedia.org/wiki/Bank_card_number#Issuer_identification_number_.28IIN.29" rel="noreferrer">detailed list of prefixes</a>)</li> </ul> <h2>Checksum</h2> <p>Most cards use the Luhn algorithm for checksums:</p> <p><a href="http://en.wikipedia.org/wiki/Luhn_algorithm" rel="noreferrer">Luhn Algorithm described on Wikipedia</a></p> <p>There are links to many implementations on the Wikipedia link, including PHP:</p> <pre><code>&lt;? /* Luhn algorithm number checker - (c) 2005-2008 shaman - www.planzero.org * * This code has been released into the public domain, however please * * give credit to the original author where possible. */ function luhn_check($number) { // Strip any non-digits (useful for credit card numbers with spaces and hyphens) $number=preg_replace('/\D/', '', $number); // Set the string length and parity $number_length=strlen($number); $parity=$number_length % 2; // Loop through each digit and do the maths $total=0; for ($i=0; $i&lt;$number_length; $i++) { $digit=$number[$i]; // Multiply alternate digits by two if ($i % 2 == $parity) { $digit*=2; // If the sum is two digits, add them together (in effect) if ($digit &gt; 9) { $digit-=9; } } // Total up the digits $total+=$digit; } // If the total mod 10 equals 0, the number is valid return ($total % 10 == 0) ? TRUE : FALSE; } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload