Created
April 16, 2016 12:03
-
-
Save bhaskarmelkani/69929f313bb3d66a34425c40743fcfb7 to your computer and use it in GitHub Desktop.
Script for validating Debit/Credit card number using Luhn's Theorem.
This file contains hidden or 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 luhn_validate(n){ | |
var l = /^[0-9]+$/.test(n)&&n.length, s = 0, b = 1; | |
while (l) | |
s += (b ^= 1) ? +[0, 2, 4, 6, 8, 1, 3, 5, 7, 9][+n[--l]] : +n[--l]; | |
return !!s && s % 10 === 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment