diff options
-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) { |