Skip to content

Instantly share code, notes, and snippets.

@jamesbjackson
Forked from OiNutter/LICENSE.txt
Created December 2, 2011 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesbjackson/1421037 to your computer and use it in GitHub Desktop.
Save jamesbjackson/1421037 to your computer and use it in GitHub Desktop.
Credit Card Validation similar to the Luhn Algorithm

Validates a credit card number based on the information given at

http://www.mint.com/blog/trends/credit-card-code-01202011/

var validCard=function(a,b,c,d) {a=a.split('').reverse();c=0;for(b in a){d=b%2!=0?a[b]2:a[b];if(d>=10)d=0|d/10+d%10;c+= d1} return c==70}

validCard('No Way I'm Putting Mine Here!!!') // returns true or false

function(
a, //credit card number
b, //placeholder
c, //placeholder
d //placeholder
) {
/*
Validates according to algorithm given here:
http://www.mint.com/blog/trends/credit-card-code-01202011/
*/
a=a.split('').reverse(); //splits and reverses the credit card number
c=0;
//loops through each digit in credit card number
for(b in a){
d=b%2!=0?a[b]*2:a[b]; // doubles every second number from right thanks to reversing of number
//if double digits, split and add digits together
if(d>=10)
d=0|d/10+d%10;
c+=+d //total up
}
return c==70 //return valid if equal to 70
}
function(a,b,c,d) {a=a.split('').reverse();c=0;for(b in a){d=b%2!=0?a[b]*2:a[b];if(d>=10)d=0|d/10+d%10;c+= d*1} return c==70}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Will McKenzie<www.oinutter.co.uk>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "creditCardValidation",
"description": "Validates a credit card.",
"keywords": [
"creditcard",
"validation",
"form",
"checksum"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment