Browse Source

#310: date validator still return valid if the value doesn't contain digits

phuoc 11 years ago
parent
commit
bbaafaea61

+ 1 - 0
CHANGELOG.md

@@ -17,6 +17,7 @@
 * [#288](https://github.com/nghuuphuoc/bootstrapvalidator/issues/288): Fix [```date``` validator](http://bootstrapvalidator.com/validators/date/) issue on IE8
 * [#292](https://github.com/nghuuphuoc/bootstrapvalidator/pull/292): Fix identical validator issue with not clearing ```has-error``` class, thanks to [@alavers](https://github.com/alavers)
 * [#305](https://github.com/nghuuphuoc/bootstrapvalidator/pull/305): Fix ```inclusive``` option in the [```lessThan``` validator](http://bootstrapvalidator.com/validators/lessThan/), thanks to [@johanronn77](https://github.com/johanronn77)
+* [#310](https://github.com/nghuuphuoc/bootstrapvalidator/issues/310): The [```date``` validator](http://bootstrapvalidator.com/validators/date/) still return valid if the value doesn't contain digits
 * [#259](https://github.com/nghuuphuoc/bootstrapvalidator/issues/259): Typo "Support almost Bootstrap forms"
 * [#261](https://github.com/nghuuphuoc/bootstrapvalidator/pull/261): English fix to 'amazing contributors' section, thanks to [@lloydde](https://github.com/lloydde)
 * [#278](https://github.com/nghuuphuoc/bootstrapvalidator/pull/278): Update [```choice``` validator](http://bootstrapvalidator.com/validators/choice/) document, thanks to [@MrC0mm0n](https://github.com/MrC0mm0n)

+ 9 - 5
dist/js/bootstrapValidator.js

@@ -1193,6 +1193,10 @@
          * @returns {Boolean}
          */
         date: function(year, month, day, notInFuture) {
+            if (isNaN(year) || isNaN(month) || isNaN(day)) {
+                return false;
+            }
+
             if (year < 1000 || year > 9999 || month == 0 || month > 12) {
                 return false;
             }
@@ -1740,7 +1744,7 @@
                 // Validate seconds
                 if (seconds) {
                     seconds = parseInt(seconds, 10);
-                    if (seconds < 0 || seconds > 60) {
+                    if (isNaN(seconds) || seconds < 0 || seconds > 60) {
                         return false;
                     }
                 }
@@ -1748,7 +1752,7 @@
                 // Validate hours
                 if (hours) {
                     hours = parseInt(hours, 10);
-                    if (hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
+                    if (isNaN(hours) || hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
                         return false;
                     }
                 }
@@ -1756,7 +1760,7 @@
                 // Validate minutes
                 if (minutes) {
                     minutes = parseInt(minutes, 10);
-                    if (minutes < 0 || minutes > 59) {
+                    if (isNaN(minutes) || minutes < 0 || minutes > 59) {
                         return false;
                     }
                 }
@@ -1991,8 +1995,8 @@
             if (value == '') {
                 return true;
             }
-            value = parseFloat(value);
-            return (options.inclusive === true) ? (value > options.value) : (value >= options.value);
+            value = parseFloat(value);           
+			return (options.inclusive === false || options.inclusive==undefined) ? (value >= options.value) : (value > options.value);
         }
     }
 }(window.jQuery));

File diff suppressed because it is too large
+ 2 - 2
dist/js/bootstrapValidator.min.js


+ 4 - 0
src/js/bootstrapValidator.js

@@ -1192,6 +1192,10 @@
          * @returns {Boolean}
          */
         date: function(year, month, day, notInFuture) {
+            if (isNaN(year) || isNaN(month) || isNaN(day)) {
+                return false;
+            }
+
             if (year < 1000 || year > 9999 || month == 0 || month > 12) {
                 return false;
             }

+ 3 - 3
src/js/validator/date.js

@@ -71,7 +71,7 @@
                 // Validate seconds
                 if (seconds) {
                     seconds = parseInt(seconds, 10);
-                    if (seconds < 0 || seconds > 60) {
+                    if (isNaN(seconds) || seconds < 0 || seconds > 60) {
                         return false;
                     }
                 }
@@ -79,7 +79,7 @@
                 // Validate hours
                 if (hours) {
                     hours = parseInt(hours, 10);
-                    if (hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
+                    if (isNaN(hours) || hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
                         return false;
                     }
                 }
@@ -87,7 +87,7 @@
                 // Validate minutes
                 if (minutes) {
                     minutes = parseInt(minutes, 10);
-                    if (minutes < 0 || minutes > 59) {
+                    if (isNaN(minutes) || minutes < 0 || minutes > 59) {
                         return false;
                     }
                 }