summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. 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)
commit5a57784164e5b96d17f85a3012e48bb462d56c42 (patch)
tree95d3e5f6cd59972586ccafc63b2930c14715132b
parentdf0fce756247e9598c57354b764bdaf1ce709038 (diff)
downloadepirts.js-5a57784164e5b96d17f85a3012e48bb462d56c42.zip
epirts.js-5a57784164e5b96d17f85a3012e48bb462d56c42.tar.gz
epirts.js-5a57784164e5b96d17f85a3012e48bb462d56c42.tar.bz2
Epirts.card.luhnCheck(): Implement
-rw-r--r--epirts.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/epirts.js b/epirts.js
index 3db67d0..7053626 100644
--- a/epirts.js
+++ b/epirts.js
@@ -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) {
};