Skip to content

Instantly share code, notes, and snippets.

@takustaqu
Created October 24, 2015 16:22
Show Gist options
  • Save takustaqu/bb26cda63996809102e2 to your computer and use it in GitHub Desktop.
Save takustaqu/bb26cda63996809102e2 to your computer and use it in GitHub Desktop.
Luhn Validation Logic on JavaScript
function luhnValidate(input){
var tmp = 0,i,il,cur,head;
for(i=0,il=input.length;i<il;i++){
cur = parseInt(input[il-i-1])*(i%2 ? 2 : 1);
head = Math.floor(cur/10);
tmp += head + (cur - head *10);
}
return !(tmp % 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment