Free Script for Validating a Credit Card
This is a free PHP script that will return true or false, depending on whether or not a valid credit card number is passed to it.
<?php
function isCreditCard($st) {
if ($st == 0)
return (false);
if (strlen($st) > 19)
return (false);
$sum = 0; $mul = 1; $l = strlen($st);
for ($i = 0; $i < $l; $i++) {
$digit = substr($st, $l-$i-1, 1);
$tproduct = $digit*$mul;
if ($tproduct >= 10)
$sum += ($tproduct % 10) + 1;
else
$sum += $tproduct;
if ($mul == 1)
$mul++;
else
$mul--;
}
if (($sum % 10) == 0)
return (true);
else
return (false);
}
?>