phuoc 11 年之前
父节点
当前提交
ce768ab2d3

文件差异内容过多而无法显示
+ 1 - 1
CHANGELOG.md


+ 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.0-dev, built on 2014-07-07 6:50:25 PM
+ * @version     v0.5.0-dev, built on 2014-07-08 4:05:10 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 9 - 1
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.0-dev, built on 2014-07-07 6:50:25 PM
+ * @version     v0.5.0-dev, built on 2014-07-08 4:05:10 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -2311,10 +2311,18 @@
             // Determine the date
             date       = date.split(separator);
             dateFormat = dateFormat.split(separator);
+            if (date.length !== dateFormat.length) {
+                return false;
+            }
+
             var year  = date[$.inArray('YYYY', dateFormat)],
                 month = date[$.inArray('MM', dateFormat)],
                 day   = date[$.inArray('DD', dateFormat)];
 
+            if (!year || !month || !day) {
+                return false;
+            }
+
             // Determine the time
             var minutes = null, hours = null, seconds = null;
             if (timeFormat) {

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


+ 8 - 0
src/js/validator/date.js

@@ -60,10 +60,18 @@
             // Determine the date
             date       = date.split(separator);
             dateFormat = dateFormat.split(separator);
+            if (date.length !== dateFormat.length) {
+                return false;
+            }
+
             var year  = date[$.inArray('YYYY', dateFormat)],
                 month = date[$.inArray('MM', dateFormat)],
                 day   = date[$.inArray('DD', dateFormat)];
 
+            if (!year || !month || !day) {
+                return false;
+            }
+
             // Determine the time
             var minutes = null, hours = null, seconds = null;
             if (timeFormat) {

+ 39 - 0
test/spec.js

@@ -1803,6 +1803,45 @@ describe('date', function() {
         this.$date.val('2004df/1dd1/5ffg');
         this.bv.validate();
         expect(this.bv.isValid()).toEqual(false);
+
+        // #475
+        this.bv.resetForm();
+        this.$date.val('2014/09');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+
+        this.bv.resetForm();
+        this.$date.val('2014/09/');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+
+        this.bv.resetForm();
+        this.$date.val('2014//15');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+
+        this.bv.resetForm();
+        this.$date.val('/09/15');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+    });
+
+    it('MM/DD/YYYY', function() {
+        this.bv.updateOption('date', 'date', 'format', 'MM/DD/YYYY');
+
+        this.$date.val('09/15/2020');
+        this.bv.validate();
+        expect(this.bv.isValid()).toBeTruthy();
+
+        this.bv.resetForm();
+        this.$date.val('09/15');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+
+        this.bv.resetForm();
+        this.$date.val('09/15/');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
     });
 
     it('number of days in February', function() {

+ 39 - 0
test/spec/validator/date.js

@@ -65,6 +65,45 @@ describe('date', function() {
         this.$date.val('2004df/1dd1/5ffg');
         this.bv.validate();
         expect(this.bv.isValid()).toEqual(false);
+
+        // #475
+        this.bv.resetForm();
+        this.$date.val('2014/09');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+
+        this.bv.resetForm();
+        this.$date.val('2014/09/');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+
+        this.bv.resetForm();
+        this.$date.val('2014//15');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+
+        this.bv.resetForm();
+        this.$date.val('/09/15');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+    });
+
+    it('MM/DD/YYYY', function() {
+        this.bv.updateOption('date', 'date', 'format', 'MM/DD/YYYY');
+
+        this.$date.val('09/15/2020');
+        this.bv.validate();
+        expect(this.bv.isValid()).toBeTruthy();
+
+        this.bv.resetForm();
+        this.$date.val('09/15');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+
+        this.bv.resetForm();
+        this.$date.val('09/15/');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
     });
 
     it('number of days in February', function() {