diff options
author | P. J. McDermott <pj@pehjota.net> | 2015-03-15 22:03:40 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2015-03-15 22:03:40 (EDT) |
commit | 5a57784164e5b96d17f85a3012e48bb462d56c42 (patch) | |
tree | 95d3e5f6cd59972586ccafc63b2930c14715132b | |
parent | df0fce756247e9598c57354b764bdaf1ce709038 (diff) | |
download | epirts.js-5a57784164e5b96d17f85a3012e48bb462d56c42.zip epirts.js-5a57784164e5b96d17f85a3012e48bb462d56c42.tar.gz epirts.js-5a57784164e5b96d17f85a3012e48bb462d56c42.tar.bz2 |
Epirts.card.luhnCheck(): Implement
-rw-r--r-- | epirts.js | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -44,6 +44,25 @@ var Stripe = Epirts = (function() { pub.validateCardNumber = function(number) { }; + pub.luhnCheck = function(number) { + var i; + var digit; + var sum; + + number += ''; + sum = 0; + for (i = 0; i < number.length; ++i) { + digit = number.charAt(number.length - 1 - i); + digit = parseInt(digit); + digit *= i % 2 + 1; + if (digit > 9) { + digit -= 9; + } + sum += digit; + } + return sum % 10 === 0; + }; + pub.validateExpiry = function(month, year) { }; |