Skip to content

Instantly share code, notes, and snippets.

@neilxp
Created December 13, 2011 02:55
Show Gist options
  • Save neilxp/1470283 to your computer and use it in GitHub Desktop.
Save neilxp/1470283 to your computer and use it in GitHub Desktop.
credit card number checking
CreditCard: {
TEST_NUMBERS: $w('378282246310005 371449635398431 378734493671000 30569309025904 38520000023237 6011111111111117 6011000990139424 5555555555554444 5105105105105100 4111111111111111 4012888888881881 4222222222222'),
isValid: function(number){
if (number.blank()) return false;
if (Braintree.CreditCard.TEST_NUMBERS.include(number)) return false;
var total = ($A(number).reverse().inject(0, function(a, n, index) {
return a + $A((parseInt(n) * [1, 2][index % 2]).toString()).inject(0, function(b, o) {
return b + parseInt(o);
});
}));
return total % 10 == 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment