浏览代码

#232: Validate Spanish personal identity code (DNI)

phuoc 11 年之前
父节点
当前提交
e969e36fa4
共有 3 个文件被更改,包括 42 次插入2 次删除
  1. 20 0
      dist/js/bootstrapValidator.js
  2. 2 2
      dist/js/bootstrapValidator.min.js
  3. 20 0
      src/js/validator/id.js

+ 20 - 0
dist/js/bootstrapValidator.js

@@ -1807,6 +1807,7 @@
         /**
         /**
          * Validate identification number in different countries
          * Validate identification number in different countries
          *
          *
+         * @see http://en.wikipedia.org/wiki/National_identification_number
          * @param {BootstrapValidator} validator The validator plugin instance
          * @param {BootstrapValidator} validator The validator plugin instance
          * @param {jQuery} $field Field element
          * @param {jQuery} $field Field element
          * @param {Object} options Consist of key:
          * @param {Object} options Consist of key:
@@ -1957,6 +1958,25 @@
             }
             }
 
 
             return true;
             return true;
+        },
+
+        /**
+         * Validate Spanish personal identity code (DNI)
+         * Examples:
+         * - Valid: 54362315K, 54362315-K
+         * - Invalid: 54362315Z
+         *
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _es: function(value) {
+            if (!/^[0-9A-Z]{8}[-]{0,1}[0-9A-Z]{1}$/.test(value)) {
+                return false;
+            }
+            value = value.replace(/-/g, '');
+            var check = parseInt(value.substr(0, 8), 10);
+            check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
+            return (check == value.substr(8, 1));
         }
         }
     };
     };
 }(window.jQuery));
 }(window.jQuery));

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


+ 20 - 0
src/js/validator/id.js

@@ -8,6 +8,7 @@
         /**
         /**
          * Validate identification number in different countries
          * Validate identification number in different countries
          *
          *
+         * @see http://en.wikipedia.org/wiki/National_identification_number
          * @param {BootstrapValidator} validator The validator plugin instance
          * @param {BootstrapValidator} validator The validator plugin instance
          * @param {jQuery} $field Field element
          * @param {jQuery} $field Field element
          * @param {Object} options Consist of key:
          * @param {Object} options Consist of key:
@@ -158,6 +159,25 @@
             }
             }
 
 
             return true;
             return true;
+        },
+
+        /**
+         * Validate Spanish personal identity code (DNI)
+         * Examples:
+         * - Valid: 54362315K, 54362315-K
+         * - Invalid: 54362315Z
+         *
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _es: function(value) {
+            if (!/^[0-9A-Z]{8}[-]{0,1}[0-9A-Z]{1}$/.test(value)) {
+                return false;
+            }
+            value = value.replace(/-/g, '');
+            var check = parseInt(value.substr(0, 8), 10);
+            check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
+            return (check == value.substr(8, 1));
         }
         }
     };
     };
 }(window.jQuery));
 }(window.jQuery));