浏览代码

#138: Add hex validator

nghuuphuoc 11 年之前
父节点
当前提交
b175903ed3
共有 3 个文件被更改,包括 43 次插入1 次删除
  1. 21 0
      dist/js/bootstrapValidator.js
  2. 1 1
      dist/js/bootstrapValidator.min.js
  3. 21 0
      src/js/validator/hex.js

+ 21 - 0
dist/js/bootstrapValidator.js

@@ -1291,6 +1291,27 @@
     }
 }(window.jQuery));
 ;(function($) {
+    $.fn.bootstrapValidator.validators.hex = {
+        /**
+         * Return true if and only if the input value is a valid hexadecimal number
+         *
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options Consist of key:
+         * - message: The invalid message
+         * @returns {Boolean}
+         */
+        validate: function(validator, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+
+            return /^[0-9a-fA-F]+$/.test(value);
+        }
+    };
+}(window.jQuery));
+;(function($) {
     $.fn.bootstrapValidator.validators.hexColor = {
         enableByHtml5: function($field) {
             return ('color' == $field.attr('type'));

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


+ 21 - 0
src/js/validator/hex.js

@@ -0,0 +1,21 @@
+(function($) {
+    $.fn.bootstrapValidator.validators.hex = {
+        /**
+         * Return true if and only if the input value is a valid hexadecimal number
+         *
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options Consist of key:
+         * - message: The invalid message
+         * @returns {Boolean}
+         */
+        validate: function(validator, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+
+            return /^[0-9a-fA-F]+$/.test(value);
+        }
+    };
+}(window.jQuery));