Skip to content

Instantly share code, notes, and snippets.

@arempe93
Created February 22, 2016 20:26
Show Gist options
  • Save arempe93/d135655360817f84fcce to your computer and use it in GitHub Desktop.
Save arempe93/d135655360817f84fcce to your computer and use it in GitHub Desktop.
Javascript credit card validator using Luhn's Algorithm
function isValidCreditCard(number) {
var len = number.length,
multiply = 1,
sum = 0,
val;
while (len--) {
val = parseInt(number.charAt(len), 10);
sum += (multiply ^= 1) ? Math.trunc(val * 2 / 10) + (val * 2 % 10) : val;
}
return sum && sum % 10 == 0;
}
@arempe93
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment