浏览代码

#112: Fix creditCard validator

nghuuphuoc 11 年之前
父节点
当前提交
f2cb18a94a
共有 3 个文件被更改,包括 15 次插入13 次删除
  1. 7 6
      dist/js/bootstrapValidator.js
  2. 1 1
      dist/js/bootstrapValidator.min.js
  3. 7 6
      src/js/validator/creditCard.js

+ 7 - 6
dist/js/bootstrapValidator.js

@@ -689,7 +689,7 @@
                 return false;
             }
 
-            // Validate the card number based on pattern
+            // Validate the card number based on prefix and length
             var cards = {
                 AMERICAN_EXPRESS: {
                     length: [15],
@@ -740,15 +740,16 @@
                           '622920', '622921', '622922', '622923', '622924', '622925']
                 },
                 VISA: {
-                    length: ['16'],
+                    length: [16],
                     ccv: ['4']
                 }
             };
-            var type, prefix;
+
+            var type, i;
             for (type in cards) {
-                for (prefix in cards[type]['ccv']) {
-                    if (value.substr(0, prefix.length) == prefix                // Check the prefix
-                        && cards[type]['length'].indexOf(value.length) != -1)   // and length
+                for (i in cards[type]['ccv']) {
+                    if (value.substr(0, cards[type]['ccv'][i].length) == cards[type]['ccv'][i]  // Check the prefix
+                        && cards[type]['length'].indexOf(value.length) != -1)                   // and length
                     {
                         return true;
                     }

文件差异内容过多而无法显示
+ 1 - 1
dist/js/bootstrapValidator.min.js


+ 7 - 6
src/js/validator/creditCard.js

@@ -44,7 +44,7 @@
                 return false;
             }
 
-            // Validate the card number based on pattern
+            // Validate the card number based on prefix and length
             var cards = {
                 AMERICAN_EXPRESS: {
                     length: [15],
@@ -95,15 +95,16 @@
                           '622920', '622921', '622922', '622923', '622924', '622925']
                 },
                 VISA: {
-                    length: ['16'],
+                    length: [16],
                     ccv: ['4']
                 }
             };
-            var type, prefix;
+
+            var type, i;
             for (type in cards) {
-                for (prefix in cards[type]['ccv']) {
-                    if (value.substr(0, prefix.length) == prefix                // Check the prefix
-                        && cards[type]['length'].indexOf(value.length) != -1)   // and length
+                for (i in cards[type]['ccv']) {
+                    if (value.substr(0, cards[type]['ccv'][i].length) == cards[type]['ccv'][i]  // Check the prefix
+                        && cards[type]['length'].indexOf(value.length) != -1)                   // and length
                     {
                         return true;
                     }