浏览代码

#232: Validate Swedish personal identity number (personnummer)

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

+ 27 - 0
dist/js/bootstrapValidator.js

@@ -2163,6 +2163,33 @@
         },
 
         /**
+         * Validate Swedish personal identity number (personnummer)
+         * Examples:
+         * - Valid: 8112289874, 811228-9874, 811228+9874
+         * - Invalid: 811228-9873
+         *
+         * @see http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _se: function(value) {
+            if (!/^[0-9]{10}$/.test(value) && !/^[0-9]{6}[-|+][0-9]{4}$/.test(value)) {
+                return false;
+            }
+            value = value.replace(/[^0-9]/g, '');
+
+            var year  = parseInt(value.substr(0, 2)) + 1900,
+                month = parseInt(value.substr(2, 2)),
+                day   = parseInt(value.substr(4, 2));
+            if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
+                return false;
+            }
+
+            // Validate the last check digit
+            return $.fn.bootstrapValidator.helpers.luhn(value);
+        },
+
+        /**
          * Validate San Marino citizen number
          *
          * @see http://en.wikipedia.org/wiki/National_identification_number#San_Marino

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


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

@@ -353,6 +353,33 @@
         },
 
         /**
+         * Validate Swedish personal identity number (personnummer)
+         * Examples:
+         * - Valid: 8112289874, 811228-9874, 811228+9874
+         * - Invalid: 811228-9873
+         *
+         * @see http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _se: function(value) {
+            if (!/^[0-9]{10}$/.test(value) && !/^[0-9]{6}[-|+][0-9]{4}$/.test(value)) {
+                return false;
+            }
+            value = value.replace(/[^0-9]/g, '');
+
+            var year  = parseInt(value.substr(0, 2)) + 1900,
+                month = parseInt(value.substr(2, 2)),
+                day   = parseInt(value.substr(4, 2));
+            if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
+                return false;
+            }
+
+            // Validate the last check digit
+            return $.fn.bootstrapValidator.helpers.luhn(value);
+        },
+
+        /**
          * Validate San Marino citizen number
          *
          * @see http://en.wikipedia.org/wiki/National_identification_number#San_Marino