Try this:

  function do_mod_10($num)
    // The Luhn formula works right to left, so reverse the number.
    $num = strrev($num);
    $total = 0;
    for ($i = 0, $j = 1; $i < strlen($num); $i++, $j=3-$j)
      $digit = $num[$i] * $j;
      if ($digit > 9)  $digit -= 9;
      $total += $digit;

    return ($total % 10 == 0);

-----Original Message-----
From: Mark McCulligh [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 24, 2002 10:47 AM
Subject: [PHP] Re: Credit card checks?

You could use an algorithms called mod10.  Both Visa, MasterCard and I think
most other credit cards use the mod10 algorithm.  A credit card must pass a
mod10 test to be a valid number(Like a Regular Expression test).  It won't
tell you if the number exist, but it will tell you if it could exist.  I
also know the mod10 is used for Canadian Social Security numbers (SIN).

Unfortunately I have never seen a PHP function for it, I only used mod10 in
a language called Uniface by Compuware.   I know there is another name for
it also, but I can't remember it right now.

It is a great test, someone just typing in numbers at random will have a
terrible time guessing a number right.  I have never seen someone do it let.
Then you can use the first character of the number to test the card type.

I will see if I can locate the algorithm and email it too you.


"Jas" <[EMAIL PROTECTED]> wrote in message
> Just wondering if anyone has come across the need to develop a class to
> a string of numbers based on a credit card type.  If you have where would
> be able to get information on what string of numbers is consistent with
> of the different credit cards?  Any help would be appreciated!
> Jas

PHP General Mailing List (
To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to