diff options
author | P. J. McDermott <pj@pehjota.net> | 2015-03-15 22:04:19 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2015-03-15 22:04:19 (EDT) |
commit | 6e80eb984c973fb5675a8ad143a68ae9254469fa (patch) | |
tree | 4f3c04e8503d4c8d761e865500c5311122b1e7bf | |
parent | 5a57784164e5b96d17f85a3012e48bb462d56c42 (diff) | |
download | epirts.js-6e80eb984c973fb5675a8ad143a68ae9254469fa.zip epirts.js-6e80eb984c973fb5675a8ad143a68ae9254469fa.tar.gz epirts.js-6e80eb984c973fb5675a8ad143a68ae9254469fa.tar.bz2 |
Epirts.card.validateCardNumber(): Implement
-rw-r--r-- | epirts.js | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -42,6 +42,23 @@ var Stripe = Epirts = (function() { }; pub.validateCardNumber = function(number) { + number = (number + '').replace(/\s|-/g); + if (number.match(/\D/)) { + return false; + } else if (number.length < 13 || number.length > 16) { + /* Card number lengths: + * * VISA: 13 or 16 + * * MasterCard: 16 + * * American Express: 15 + * * JCB: 16 + * * Discover: 16 + * * Diners Club: 14-16 + */ + return false; + } else if (!pub.luhnCheck(number)) { + return false; + } + return true; }; pub.luhnCheck = function(number) { |