ISN (International Social Networking Services - Interactive Apps and Websites)

Validation function for LUHNMod10 and variant


function prestoLUHN($ccn="",$alt="0") 
// pre-validations 
$ccn = ereg_replace("[^[:digit:]]+", "", $ccn); 
if ((strlen($ccn) < 1)) return FALSE; 
// Mapping: Double-then-SumOfDigits  (0123456789) => (0246813579) 
for($i=0;$i<=9;$i++) $v[$i] = (($i*2)<9) ? ($i*2):($i*2)-9; 
// Initial value of $alt (Alternation Pattern) determines which digits are transformed by $v[] during checksum calculation 
// 0 = apply transform to even-numbered digits from LSD-to-MSD (Conventional LUHNMod10) 
// 1 = apply transform to  odd-numbered digits from LSD-to-MSD (alternative) 
$checksum = 0;      
// Calculate checksum from the end of the string (the low-order digit) to beginning of string 
for($i = strlen($ccn)-1; $i >= 0; $i--) 
   $digit = substr($ccn, $i, 1); 
   $checksum += $alt ? $v[$digit] : $digit; 
   $alt ^= 1; 
// return the checksum descrimination result 
return !($checksum % 10);       
By continuing to use this site, you agree to the use of cookies to personalize content and advertisements, to provide social media functionality, to analyze our traffic using Google services like Analytics and Adsense.

Google Adsense and its partners may use your data for advertising personalization and cookies may be used for personalized and non-personalized advertising. How does Google use my data?
Please use the following button to see the list of Google partners as well as all the details regarding cookies.
See detailsI Accept
These cookies are mandatory for the operation of, if you do not accept them please quit this site.
You have the right to refuse cookies and leave the site or to change the parameters.