Created
October 24, 2015 16:22
-
-
Save takustaqu/bb26cda63996809102e2 to your computer and use it in GitHub Desktop.
Luhn Validation Logic on JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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