As I mentioned before, the Luhn algorithm is used to validate some interesting numbers, most notably GSM IMEIs and credit card numbers. Here’s another implementation I wrote, this time in PHP.
function luhn($str) { $odd = !strlen($str)%2; $sum = 0; for($i=0;$i<strlen($str);++$i) { $n=0+$str[$i]; $odd=!$odd; if($odd) { $sum+=$n; } else { $x=2*$n; $sum+=$x>9?$x-9:$x; } } return(($sum%10)==0); }
(Download)