浏览代码

#252: Add ```sedol``` (Stock Exchange Daily Official List) validator

nghuuphuoc 11 年之前
父节点
当前提交
2766cc30ad
共有 4 个文件被更改,包括 74 次插入1 次删除
  1. 1 0
      CHANGELOG.md
  2. 36 0
      dist/js/bootstrapValidator.js
  3. 1 1
      dist/js/bootstrapValidator.min.js
  4. 36 0
      src/js/validator/sedol.js

+ 1 - 0
CHANGELOG.md

@@ -7,6 +7,7 @@
 * [#232](https://github.com/nghuuphuoc/bootstrapvalidator/issues/232): Add ```id``` validator
 * [#242](https://github.com/nghuuphuoc/bootstrapvalidator/issues/242): Add ```separator``` option to the [```numeric``` validator](http://bootstrapvalidator.com/validators/numeric/)
 * [#248](https://github.com/nghuuphuoc/bootstrapvalidator/issues/248): Add ```isin``` (International Securities Identification Number) validator
+* [#252](https://github.com/nghuuphuoc/bootstrapvalidator/issues/252): Add ```sedol``` (Stock Exchange Daily Official List) validator
 * The [```zipCode``` validator](http://bootstrapvalidator.com/validators/zipCode/) adds support for Italian, Dutch postcodes
 * [#245](https://github.com/nghuuphuoc/bootstrapvalidator/pull/245): The [```cvv``` validator](http://bootstrapvalidator.com/validators/cvv/) should support spaces in credit card, thanks to [@evilchili](https://github.com/evilchili)
 * Change default ```submitButtons``` to ```[type="submit"]``` to support ```input type="submit"```

+ 36 - 0
dist/js/bootstrapValidator.js

@@ -3222,6 +3222,42 @@
     };
 }(window.jQuery));
 ;(function($) {
+    $.fn.bootstrapValidator.validators.sedol = {
+        /**
+         * Validate a SEDOL (Stock Exchange Daily Official List)
+         * Examples:
+         * - Valid: 0263494, B0WNLY7
+         *
+         * @see http://en.wikipedia.org/wiki/SEDOL
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options Can consist of the following keys:
+         * - message: The invalid message
+         * @returns {Boolean}
+         */
+        validate: function(validator, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+
+            value = value.toUpperCase();
+            if (!/^[0-9A-Z]{7}$/.test(value)) {
+                return false;
+            }
+
+            var sum    = 0,
+                weight = [1, 3, 1, 7, 3, 9, 1],
+                length = value.length;
+            for (var i = 0; i < length - 1; i++) {
+	            sum += weight[i] * parseInt(value.charAt(i), 36);
+	        }
+	        sum = (10 - sum % 10) % 10;
+            return sum == value.charAt(length - 1);
+        }
+    };
+}(window.jQuery));
+;(function($) {
 	$.fn.bootstrapValidator.validators.siren = {
 		/**
 		 * Check if a string is a siren number

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


+ 36 - 0
src/js/validator/sedol.js

@@ -0,0 +1,36 @@
+(function($) {
+    $.fn.bootstrapValidator.validators.sedol = {
+        /**
+         * Validate a SEDOL (Stock Exchange Daily Official List)
+         * Examples:
+         * - Valid: 0263494, B0WNLY7
+         *
+         * @see http://en.wikipedia.org/wiki/SEDOL
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options Can consist of the following keys:
+         * - message: The invalid message
+         * @returns {Boolean}
+         */
+        validate: function(validator, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+
+            value = value.toUpperCase();
+            if (!/^[0-9A-Z]{7}$/.test(value)) {
+                return false;
+            }
+
+            var sum    = 0,
+                weight = [1, 3, 1, 7, 3, 9, 1],
+                length = value.length;
+            for (var i = 0; i < length - 1; i++) {
+	            sum += weight[i] * parseInt(value.charAt(i), 36);
+	        }
+	        sum = (10 - sum % 10) % 10;
+            return sum == value.charAt(length - 1);
+        }
+    };
+}(window.jQuery));