浏览代码

#250: Add ```rtn``` (Routing transit number) validator

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

+ 1 - 0
CHANGELOG.md

@@ -7,6 +7,7 @@
 * [#232](https://github.com/nghuuphuoc/bootstrapvalidator/issues/232): Add ```id``` validator
 * [#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/)
 * [#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
 * [#248](https://github.com/nghuuphuoc/bootstrapvalidator/issues/248): Add ```isin``` (International Securities Identification Number) validator
+* [#250](https://github.com/nghuuphuoc/bootstrapvalidator/issues/250): Add ```rtn``` (Routing transit number) validator
 * [#251](https://github.com/nghuuphuoc/bootstrapvalidator/issues/251): Add ```cusip``` (North American Securities) validator
 * [#251](https://github.com/nghuuphuoc/bootstrapvalidator/issues/251): Add ```cusip``` (North American Securities) validator
 * [#252](https://github.com/nghuuphuoc/bootstrapvalidator/issues/252): Add ```sedol``` (Stock Exchange Daily Official List) 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
 * The [```zipCode``` validator](http://bootstrapvalidator.com/validators/zipCode/) adds support for Italian, Dutch postcodes

+ 34 - 0
dist/js/bootstrapValidator.js

@@ -3274,6 +3274,40 @@
     };
     };
 }(window.jQuery));
 }(window.jQuery));
 ;(function($) {
 ;(function($) {
+    $.fn.bootstrapValidator.validators.rtn = {
+        /**
+         * Validate a RTN (Routing transit number)
+         * Examples:
+         * - Valid: 021200025, 789456124
+         *
+         * @see http://en.wikipedia.org/wiki/Routing_transit_number
+         * @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;
+            }
+
+            if (!/^\d{9}$/.test(value)) {
+                return false;
+            }
+
+            var sum = 0;
+            for (var i = 0; i < value.length; i += 3) {
+                sum += parseInt(value.charAt(i),     10) * 3
+                    +  parseInt(value.charAt(i + 1), 10) * 7
+                    +  parseInt(value.charAt(i + 2), 10);
+            }
+            return (sum != 0 && sum % 10 == 0);
+        }
+    };
+}(window.jQuery));
+;(function($) {
     $.fn.bootstrapValidator.validators.sedol = {
     $.fn.bootstrapValidator.validators.sedol = {
         /**
         /**
          * Validate a SEDOL (Stock Exchange Daily Official List)
          * Validate a SEDOL (Stock Exchange Daily Official List)

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


+ 34 - 0
src/js/validator/rtn.js

@@ -0,0 +1,34 @@
+(function($) {
+    $.fn.bootstrapValidator.validators.rtn = {
+        /**
+         * Validate a RTN (Routing transit number)
+         * Examples:
+         * - Valid: 021200025, 789456124
+         *
+         * @see http://en.wikipedia.org/wiki/Routing_transit_number
+         * @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;
+            }
+
+            if (!/^\d{9}$/.test(value)) {
+                return false;
+            }
+
+            var sum = 0;
+            for (var i = 0; i < value.length; i += 3) {
+                sum += parseInt(value.charAt(i),     10) * 3
+                    +  parseInt(value.charAt(i + 1), 10) * 7
+                    +  parseInt(value.charAt(i + 2), 10);
+            }
+            return (sum != 0 && sum % 10 == 0);
+        }
+    };
+}(window.jQuery));