summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. 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)
commit6e80eb984c973fb5675a8ad143a68ae9254469fa (patch)
tree4f3c04e8503d4c8d761e865500c5311122b1e7bf
parent5a57784164e5b96d17f85a3012e48bb462d56c42 (diff)
downloadepirts.js-6e80eb984c973fb5675a8ad143a68ae9254469fa.zip
epirts.js-6e80eb984c973fb5675a8ad143a68ae9254469fa.tar.gz
epirts.js-6e80eb984c973fb5675a8ad143a68ae9254469fa.tar.bz2
Epirts.card.validateCardNumber(): Implement
-rw-r--r--epirts.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/epirts.js b/epirts.js
index 7053626..9a538af 100644
--- a/epirts.js
+++ b/epirts.js
@@ -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) {