Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hglattergotz
Created November 10, 2011 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hglattergotz/1355906 to your computer and use it in GitHub Desktop.
Save hglattergotz/1355906 to your computer and use it in GitHub Desktop.
function isCreditCard( CC ) {
var sum, mul, l, digit, tproduct, i;
if (CC.length > 19)
return (false);
sum = 0; mul = 1; l = CC.length;
for (i = 0; i < l; i++) {
digit = CC.substring(l-i-1, l-i);
tproduct = parseInt(digit, 10) * mul;
sum += (tproduct >= 10) ? (tproduct % 10) + 1 : tproduct;
(mul == 1) ? mul++ : mul--;
}
return ((sum % 10) === 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment