Skip to content

Instantly share code, notes, and snippets.

@tevashov
Last active October 27, 2022 21:31
Show Gist options
  • Select an option

  • Save tevashov/5172490 to your computer and use it in GitHub Desktop.

Select an option

Save tevashov/5172490 to your computer and use it in GitHub Desktop.
Validate Credit Card #JS
function isCreditCard( CC ){
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;
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment