Browse Source

Credit card validator uses luhn helper

phuoc 11 years ago
parent
commit
b66fc648ee
2 changed files with 2 additions and 20 deletions
  1. 1 1
      src/js/bootstrapValidator.js
  2. 1 19
      src/js/validator/creditCard.js

+ 1 - 1
src/js/bootstrapValidator.js

@@ -791,7 +791,7 @@
     // Helper methods, which can be used in validator class
     // Helper methods, which can be used in validator class
     $.fn.bootstrapValidator.helpers = {
     $.fn.bootstrapValidator.helpers = {
         /**
         /**
-         * Implement Luhn validation algorithm
+         * Implement Luhn validation algorithm ((http://en.wikipedia.org/wiki/Luhn))
          * Credit to https://gist.github.com/ShirtlessKirk/2134376
          * Credit to https://gist.github.com/ShirtlessKirk/2134376
          *
          *
          * @param {String} value
          * @param {String} value

+ 1 - 19
src/js/validator/creditCard.js

@@ -22,25 +22,7 @@
             }
             }
             value = value.replace(/\D/g, '');
             value = value.replace(/\D/g, '');
 
 
-            // Validate the check sum
-            // The Luhn Algorithm
-            // http://en.wikipedia.org/wiki/Luhn
-            var check = 0, digit = 0, even = false, length = value.length;
-
-            for (var n = length - 1; n >= 0; n--) {
-                digit = parseInt(value.charAt(n), 10);
-
-                if (even) {
-                    if ((digit *= 2) > 9) {
-                        digit -= 9;
-                    }
-                }
-
-                check += digit;
-                even = !even;
-            }
-
-            if ((check % 10) != 0) {
+            if (!$.fn.bootstrapValidator.helpers.luhn(value)) {
                 return false;
                 return false;
             }
             }