浏览代码

#700: between, greaterThan, lessThan validators accept param which isn't number

Phuoc Nguyen 11 年之前
父节点
当前提交
2c072f35e8

+ 1 - 0
CHANGELOG.md

@@ -36,6 +36,7 @@ __Bug Fixes__
 * [#672](https://github.com/nghuuphuoc/bootstrapvalidator/issues/672): The [zipCode](http://bootstrapvalidator.com/validators/zipCode/) validator throw an exception when passing not supported country code
 * [#681](https://github.com/nghuuphuoc/bootstrapvalidator/issues/681): Fix the [date](http://bootstrapvalidator.com/validators/date/) validator issue where one of date/month/year or hours/minutes/seconds is prefixed by zero
 * [#692](https://github.com/nghuuphuoc/bootstrapvalidator/issues/692): The [remote](http://bootstrapvalidator.com/validators/remote/) validator can't set the type option via HTML attribute
+* [#700](https://github.com/nghuuphuoc/bootstrapvalidator/issues/700): The [between](http://bootstrapvalidator.com/validators/between/), [greaterThan](http://bootstrapvalidator.com/validators/greaterThan/), [lessThan](http://bootstrapvalidator.com/validators/lessThan/) validators accept param which isn't number
 
 __Language Packages__
 

+ 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.1-dev, built on 2014-08-19 10:49:12 PM
+ * @version     v0.5.1-dev, built on 2014-08-21 1:54:13 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 10 - 4
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.1-dev, built on 2014-08-19 10:49:12 PM
+ * @version     v0.5.1-dev, built on 2014-08-21 1:54:13 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -1940,10 +1940,12 @@
             if (value === '') {
                 return true;
             }
+            if (!$.isNumeric(value)) {
+                return false;
+            }
 
             var min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
                 max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max);
-
             value = parseFloat(value);
 			return (options.inclusive === true || options.inclusive === undefined)
                     ? {
@@ -2722,9 +2724,11 @@
             if (value === '') {
                 return true;
             }
+            if (!$.isNumeric(value)) {
+                return false;
+            }
 
             var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value);
-
             value = parseFloat(value);
 			return (options.inclusive === true || options.inclusive === undefined)
                     ? {
@@ -4408,9 +4412,11 @@
             if (value === '') {
                 return true;
             }
+            if (!$.isNumeric(value)) {
+                return false;
+            }
 
             var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value);
-
             value = parseFloat(value);
             return (options.inclusive === true || options.inclusive === undefined)
                     ? {

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


+ 3 - 1
src/js/validator/between.js

@@ -47,10 +47,12 @@
             if (value === '') {
                 return true;
             }
+            if (!$.isNumeric(value)) {
+                return false;
+            }
 
             var min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
                 max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max);
-
             value = parseFloat(value);
 			return (options.inclusive === true || options.inclusive === undefined)
                     ? {

+ 3 - 1
src/js/validator/greaterThan.js

@@ -44,9 +44,11 @@
             if (value === '') {
                 return true;
             }
+            if (!$.isNumeric(value)) {
+                return false;
+            }
 
             var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value);
-
             value = parseFloat(value);
 			return (options.inclusive === true || options.inclusive === undefined)
                     ? {

+ 3 - 1
src/js/validator/lessThan.js

@@ -44,9 +44,11 @@
             if (value === '') {
                 return true;
             }
+            if (!$.isNumeric(value)) {
+                return false;
+            }
 
             var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value);
-
             value = parseFloat(value);
             return (options.inclusive === true || options.inclusive === undefined)
                     ? {

+ 18 - 0
test/spec.js

@@ -1843,6 +1843,12 @@ describe('between', function() {
         $('#betweenForm').bootstrapValidator('destroy').remove();
     });
 
+    it('not a number', function() {
+        this.$age.val('50abc');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+    });
+
     it('compare to value', function() {
         this.$age.val(10);
         this.bv.validate();
@@ -2410,6 +2416,12 @@ describe('greaterThan', function() {
         $('#greaterThanForm').bootstrapValidator('destroy').remove();
     });
 
+    it('not a number', function() {
+        this.$age.val('20abc');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+    });
+
     it('compare to value', function() {
         this.$age.val(10);
         this.bv.validate();
@@ -3862,6 +3874,12 @@ describe('lessThan', function() {
         $('#lessThanForm').bootstrapValidator('destroy').remove();
     });
 
+    it('not a number', function() {
+        this.$age.val('20abc');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+    });
+
     it('compare to value', function() {
         this.$age.val(120);
         this.bv.validate();

+ 6 - 0
test/spec/validator/between.js

@@ -56,6 +56,12 @@ describe('between', function() {
         $('#betweenForm').bootstrapValidator('destroy').remove();
     });
 
+    it('not a number', function() {
+        this.$age.val('50abc');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+    });
+
     it('compare to value', function() {
         this.$age.val(10);
         this.bv.validate();

+ 6 - 0
test/spec/validator/greaterThan.js

@@ -39,6 +39,12 @@ describe('greaterThan', function() {
         $('#greaterThanForm').bootstrapValidator('destroy').remove();
     });
 
+    it('not a number', function() {
+        this.$age.val('20abc');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+    });
+
     it('compare to value', function() {
         this.$age.val(10);
         this.bv.validate();

+ 6 - 0
test/spec/validator/lessThan.js

@@ -39,6 +39,12 @@ describe('lessThan', function() {
         $('#lessThanForm').bootstrapValidator('destroy').remove();
     });
 
+    it('not a number', function() {
+        this.$age.val('20abc');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+    });
+
     it('compare to value', function() {
         this.$age.val(120);
         this.bv.validate();