Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

luhn algorithm

function validateLuhn(string $number): bool
{
    $sum = 0;
    $flag = 0;

    for ($i = strlen($number) - 1; $i >= 0; $i--) {
        $add = $flag++ & 1 ? $number[$i] * 2 : $number[$i];
        $sum += $add > 9 ? $add - 9 : $add;
    }

    return $sum % 10 === 0;
}
Source by gist.github.com #
 
PREVIOUS NEXT
Tagged: #luhn #algorithm
ADD COMMENT
Topic
Name
1+2 =