浏览代码

#232: Validate Czech national identification number (RC)

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

+ 45 - 0
dist/js/bootstrapValidator.js

@@ -1912,6 +1912,51 @@
             }
             }
 
 
             return (d2 == value.charAt(10));
             return (d2 == value.charAt(10));
+        },
+
+        /**
+         * Validate Czech national identification number (RC)
+         * Examples:
+         * - Valid: 7103192745, 991231123
+         * - Invalid: 1103492745, 590312123
+         *
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _cz: function(value) {
+            if (!/^\d{9,10}$/.test(value)) {
+                return false;
+            }
+            var year  = 1900 + parseInt(value.substr(0, 2)),
+                month = parseInt(value.substr(2, 2)) % 50 % 20,
+                day   = parseInt(value.substr(4, 2));
+            if (value.length == 9) {
+                if (year >= 1980) {
+                    year -= 100;
+                }
+                if (year > 1953) {
+                    return false;
+                }
+            } else if (year < 1954) {
+                year += 100;
+            }
+
+            try {
+                var d = new Date(year, month, day);
+            } catch (ex) {
+                return false;
+            }
+
+            // Check that the birth date is not in the future
+            if (value.length == 10) {
+                var check = parseInt(value.substr(0, 9), 10) % 11;
+                if (year < 1985) {
+                    check = check % 10;
+                }
+                return (check == value.substr(9, 1));
+            }
+
+            return true;
         }
         }
     };
     };
 }(window.jQuery));
 }(window.jQuery));

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


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

@@ -113,6 +113,51 @@
             }
             }
 
 
             return (d2 == value.charAt(10));
             return (d2 == value.charAt(10));
+        },
+
+        /**
+         * Validate Czech national identification number (RC)
+         * Examples:
+         * - Valid: 7103192745, 991231123
+         * - Invalid: 1103492745, 590312123
+         *
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _cz: function(value) {
+            if (!/^\d{9,10}$/.test(value)) {
+                return false;
+            }
+            var year  = 1900 + parseInt(value.substr(0, 2)),
+                month = parseInt(value.substr(2, 2)) % 50 % 20,
+                day   = parseInt(value.substr(4, 2));
+            if (value.length == 9) {
+                if (year >= 1980) {
+                    year -= 100;
+                }
+                if (year > 1953) {
+                    return false;
+                }
+            } else if (year < 1954) {
+                year += 100;
+            }
+
+            try {
+                var d = new Date(year, month, day);
+            } catch (ex) {
+                return false;
+            }
+
+            // Check that the birth date is not in the future
+            if (value.length == 10) {
+                var check = parseInt(value.substr(0, 9), 10) % 11;
+                if (year < 1985) {
+                    check = check % 10;
+                }
+                return (check == value.substr(9, 1));
+            }
+
+            return true;
         }
         }
     };
     };
 }(window.jQuery));
 }(window.jQuery));