ソースを参照

#823: The hexColor validator only accepts 6 hex character values when using HTML 5 type='color' attribute

Phuoc Nguyen 11 年 前
コミット
446d1edf02

+ 3 - 0
CHANGELOG.md

@@ -8,6 +8,9 @@ __New Features__
 * [#844](https://github.com/nghuuphuoc/bootstrapvalidator/pull/844), [#874](https://github.com/nghuuphuoc/bootstrapvalidator/pull/874): The [stringLength](http://bootstrapvalidator.com/validators/stringLength/) validator adds option to evaluate length in UTF-8 bytes, thanks to [@thx2001r](https://github.com/thx2001r)
 * [#960](https://github.com/nghuuphuoc/bootstrapvalidator/issues/960): Add ```trim``` option for the [stringLength](http://bootstrapvalidator.com/validators/stringLength/) validator
 
+__Improvements__
+* [#823](https://github.com/nghuuphuoc/bootstrapvalidator/issues/823): The [hexColor](http://bootstrapvalidator.com/validators/hexColor/) validator only accepts 6 hex character values when using HTML 5 ```type='color'``` attribute
+
 __Bug Fixes__
 * [#933](https://github.com/nghuuphuoc/bootstrapvalidator/issues/933), [#959](https://github.com/nghuuphuoc/bootstrapvalidator/issues/959): Tooltip/popover isn't destroyed when the field is valid
 * [#991](https://github.com/nghuuphuoc/bootstrapvalidator/issues/991): The field is validated only one time when setting ```trigger: 'blur'```, ```container: 'tooltip'```

+ 1 - 1
dist/css/bootstrapValidator.min.css

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
- * @version     v0.5.3-dev, built on 2014-10-20 3:51:09 PM
+ * @version     v0.5.3-dev, built on 2014-10-20 4:14:15 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 7 - 2
dist/js/bootstrapValidator.js

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
- * @version     v0.5.3-dev, built on 2014-10-20 3:51:09 PM
+ * @version     v0.5.3-dev, built on 2014-10-20 4:14:15 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -3261,7 +3261,12 @@ if (typeof jQuery === 'undefined') {
             if (value === '') {
                 return true;
             }
-            return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
+
+            return ('color' === $field.attr('type'))
+                        // Only accept 6 hex character values due to the HTML 5 spec
+                        // See http://www.w3.org/TR/html-markup/input.color.html#input.color.attrs.value
+                        ? /^#[0-9A-F]{6}$/i.test(value)
+                        : /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
         }
     };
 }(window.jQuery));

ファイルの差分が大きいため隠しています
+ 4 - 4
dist/js/bootstrapValidator.min.js


+ 6 - 1
src/js/validator/hexColor.js

@@ -22,7 +22,12 @@
             if (value === '') {
                 return true;
             }
-            return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
+
+            return ('color' === $field.attr('type'))
+                        // Only accept 6 hex character values due to the HTML 5 spec
+                        // See http://www.w3.org/TR/html-markup/input.color.html#input.color.attrs.value
+                        ? /^#[0-9A-F]{6}$/i.test(value)
+                        : /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
         }
     };
 }(window.jQuery));