Skip to content

Commit e4f3a87

Browse files
committed
Fix some date validations, JS syntax errors.
1 parent 6df33a8 commit e4f3a87

File tree

4 files changed

+61
-44
lines changed

4 files changed

+61
-44
lines changed

additional-methods.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@ jQuery.validator.addMethod("dateITA", function(value, element) {
156156
}, "Please enter a correct date");
157157

158158
jQuery.validator.addMethod("dateNL", function(value, element) {
159-
return this.optional(element) || /^\d\d?[\.\/\-]\d\d?[\.\/\-]\d\d\d?\d?$/.test(value);
159+
return this.optional(element) || /^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test(value);
160160
}, "Vul hier een geldige datum in.");
161161

162162
jQuery.validator.addMethod("time", function(value, element) {
163-
return this.optional(element) || /^([0-1]\d|2[0-3]):([0-5]\d)$/.test(value);
163+
return this.optional(element) || /^([01]\d|2[0-3])(:[0-5]\d){1,2}$/.test(value);
164164
}, "Please enter a valid time, between 00:00 and 23:59");
165165
jQuery.validator.addMethod("time12h", function(value, element) {
166-
return this.optional(element) || /^((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))$/i.test(value);
167-
}, "Please enter a valid time, between 00:00 am and 12:00 pm");
166+
return this.optional(element) || /^((0?[1-9]|1[012])(:[0-5]\d){1,2}( ?[AP]M))$/i.test(value);
167+
}, "Please enter a valid time in 12-hour format");
168168

169169
/**
170170
* matches US phone number format
@@ -384,12 +384,9 @@ jQuery.validator.addMethod("require_from_group", function(value, element, option
384384
*
385385
*/
386386
jQuery.validator.addMethod("skip_or_fill_minimum", function(value, element, options) {
387-
var validator = this,
388-
numberRequired,
389-
selector;
390-
391-
numberRequired = options[0];
392-
selector = options[1];
387+
var validator = this;
388+
var numberRequired = options[0];
389+
var selector = options[1];
393390
var numberFilled = $(selector, element.form).filter(function() {
394391
return validator.elementValue(this);
395392
}).length;

test/index.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h1 id="qunit-header">
2121
<a href="?jquery=1.5.2">jQuery 1.5.2</a>
2222
<a href="?jquery=1.6.4">jQuery 1.6.4</a>
2323
<a href="?jquery=1.7.2">jQuery 1.7.2</a>
24-
<a href="?jquery=1.7.2">jQuery 1.8.3</a>
24+
<a href="?jquery=1.8.3">jQuery 1.8.3</a>
2525
<a href="?jquery=git">jQuery Latest (git)</a>
2626
</h1>
2727
<div>
@@ -157,10 +157,6 @@ <h2 id="qunit-userAgent"></h2>
157157
<input name="dataMessagesName" id="dataMessagesName" class="required" data-msg-required="You must enter a value here" />
158158
</form>
159159

160-
<form id="dataMessages">
161-
<input name="dataMessagesName" id="dataMessagesName" class="required" data-msg-required="You must enter a value here" />
162-
</form>
163-
164160
<div id="simplecontainer">
165161
<h3></h3>
166162
</div>

test/methods.js

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ test("url", function() {
3636
ok( method( "ftp://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
3737
ok( method( "http://www.føtex.dk/" ), "Valid url, danish unicode characters" );
3838
ok( method( "http://bösendorfer.de/" ), "Valid url, german unicode characters" );
39-
ok( method( "http://192.168.8.5" ), "Valid IP Address" )
40-
ok(!method( "http://192.168.8." ), "Invalid IP Address" )
39+
ok( method( "http://192.168.8.5" ), "Valid IP Address" );
40+
ok(!method( "http://192.168.8." ), "Invalid IP Address" );
4141
ok(!method( "http://bassistance" ), "Invalid url" ); // valid
4242
ok(!method( "http://bassistance." ), "Invalid url" ); // valid
4343
ok(!method( "http://bassistance,de" ), "Invalid url" );
@@ -53,8 +53,8 @@ test("url2 (tld optional)", function() {
5353
ok( method( "ftp://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
5454
ok( method( "http://www.føtex.dk/" ), "Valid url, danish unicode characters" );
5555
ok( method( "http://bösendorfer.de/" ), "Valid url, german unicode characters" );
56-
ok( method( "http://192.168.8.5" ), "Valid IP Address" )
57-
ok(!method( "http://192.168.8." ), "Invalid IP Address" )
56+
ok( method( "http://192.168.8.5" ), "Valid IP Address" );
57+
ok(!method( "http://192.168.8." ), "Invalid IP Address" );
5858
ok( method( "http://bassistance" ), "Invalid url" );
5959
ok( method( "http://bassistance." ), "Invalid url" );
6060
ok(!method( "http://bassistance,de" ), "Invalid url" );
@@ -232,9 +232,9 @@ test("required with dependencies", function() {
232232
var v = jQuery("#form").validate(),
233233
method = $.validator.methods.required,
234234
e = $('#hidden2, #select1, #area2, #radio1, #check2');
235-
ok( method.call( v, e[0].value, e[0], "asffsaa"), "Valid text input due to depencie not met" );
235+
ok( method.call( v, e[0].value, e[0], "asffsaa"), "Valid text input due to dependency not met" );
236236
ok(!method.call( v, e[0].value, e[0], "input"), "Invalid text input" );
237-
ok( method.call( v, e[0].value, e[0], function() { return false; }), "Valid text input due to depencie not met" );
237+
ok( method.call( v, e[0].value, e[0], function() { return false; }), "Valid text input due to dependency not met" );
238238
ok(!method.call( v, e[0].value, e[0], function() { return true; }), "Invalid text input" );
239239
ok( method.call( v, e[1].value, e[1], "asfsfa"), "Valid select due to dependency not met" );
240240
ok(!method.call( v, e[1].value, e[1], "input"), "Invalid select" );
@@ -488,7 +488,7 @@ asyncTest("remote radio correct value sent", function() {
488488
start();
489489
}
490490
}
491-
},
491+
}
492492
}
493493
});
494494

@@ -572,6 +572,21 @@ test("dateITA", function() {
572572
ok( method( "01/01/1900" ), "Valid date ITA" );
573573
ok(!method( "01/13/1990" ), "Invalid date ITA" );
574574
ok(!method( "01.01.1900" ), "Invalid date ITA" );
575+
ok(!method( "01/01/199" ), "Invalid date ITA" );
576+
});
577+
578+
test("dateNL", function() {
579+
var method = methodTest("dateNL");
580+
ok( method( "01-01-1900" ), "Valid date NL" );
581+
ok( method( "01.01.1900" ), "Valid date NL" );
582+
ok( method( "01/01/1900" ), "Valid date NL" );
583+
ok( method( "01-01-00" ), "Valid date NL" );
584+
ok( method( "1-01-1900" ), "Valid date NL" );
585+
ok( method( "10-10-1900" ), "Valid date NL" );
586+
ok(!method( "0-01-1900" ), "Invalid date NL" );
587+
ok(!method( "00-01-1900" ), "Invalid date NL" );
588+
ok(!method( "35-01-1990" ), "Invalid date NL" );
589+
ok(!method( "01.01.190" ), "Invalid date NL" );
575590
});
576591

577592
test("time", function() {
@@ -584,48 +599,58 @@ test("time", function() {
584599
ok( !method("24:00"), "Invalid time" );
585600
ok( !method("29:59"), "Invalid time" );
586601
ok( !method("30:00"), "Invalid time" );
602+
ok( !method("120:00"), "Invalid time" );
603+
ok( !method("12:001"), "Invalid time" );
604+
ok( !method("12:00a"), "Invalid time" );
587605
});
588606

589607
test("time12h", function() {
590608
var method = methodTest("time12h");
591609
ok( method("12:00 AM"), "Valid time, lower bound, am" );
592610
ok( method("11:59 AM"), "Valid time, upper bound, am" );
611+
ok( method("12:00AM"), "Valid time, no space, am" );
612+
ok( method("12:00PM"), "Valid time, no space, pm" );
593613
ok( method("12:00 PM"), "Valid time, lower bound, pm" );
594614
ok( method("11:59 PM"), "Valid time, upper bound, pm" );
595615
ok( method("11:59 am"), "Valid time, also accept lowercase" );
596616
ok( method("11:59 pm"), "Valid time, also accept lowercase" );
617+
ok( method("1:59 pm"), "Valid time, single hour, no leading 0" );
618+
ok( method("01:59 pm"), "Valid time, single hour, leading 0" );
597619
ok( !method("12:00"), "Invalid time" );
620+
ok( !method("9"), "Invalid time" );
621+
ok( !method("9 am"), "Invalid time" );
598622
ok( !method("12:61 am"), "Invalid time" );
599623
ok( !method("13:00 am"), "Invalid time" );
624+
ok( !method("00:00 am"), "Invalid time" );
600625
});
601626

602627
test("minWords", function() {
603628
var method = methodTest("minWords");
604629
ok( method("hello worlds", 2), "plain text, valid" );
605-
ok( method("<b>hello</b> world", 2), "html, valid" );
630+
ok( method("<em>hello</em> world", 2), "html, valid" );
606631
ok( !method("hello", 2), "plain text, invalid" );
607-
ok( !method("<b>world</b>", 2), "html, invalid" );
632+
ok( !method("<em>world</em>", 2), "html, invalid" );
608633
ok( !method("world <br/>", 2), "html, invalid" );
609634
});
610635

611636
test("maxWords", function() {
612637
var method = methodTest("maxWords");
613638
ok( method("hello", 2), "plain text, valid" );
614-
ok( method("<b>world</b>", 2), "html, valid" );
639+
ok( method("<em>world</em>", 2), "html, valid" );
615640
ok( method("world <br/>", 2), "html, valid" );
616641
ok( method("hello worlds", 2), "plain text, valid" );
617-
ok( method("<b>hello</b> world", 2), "html, valid" );
642+
ok( method("<em>hello</em> world", 2), "html, valid" );
618643
ok( !method("hello 123 world", 2), "plain text, invalid" );
619-
ok( !method("<b>hello</b> 123 world", 2), "html, invalid" );
644+
ok( !method("<em>hello</em> 123 world", 2), "html, invalid" );
620645
});
621646

622647
test("rangeWords", function() {
623648
var method = methodTest("rangeWords");
624649
ok( method("hello", [0, 2]), "plain text, valid" );
625650
ok( method("hello worlds", [0, 2]), "plain text, valid" );
626-
ok( method("<b>hello</b> world", [0, 2]), "html, valid" );
651+
ok( method("<em>hello</em> world", [0, 2]), "html, valid" );
627652
ok( !method("hello worlds what is up", [0, 2]), "plain text, invalid" );
628-
ok( !method("<b>Hello</b> <b>world</b> <b>hello</b>", [0, 2]), "html, invalid" );
653+
ok( !method("<em>Hello</em> <em>world</em> <em>hello</em>", [0, 2]), "html, invalid" );
629654
});
630655

631656
test("pattern", function() {
@@ -653,16 +678,15 @@ test('creditcardtypes, all', function() {
653678
}
654679
});
655680

656-
testCardTypeByNumber("4111-1111-1111-1111", "VISA", true)
657-
testCardTypeByNumber("5111-1111-1111-1118", "MasterCard", true)
658-
testCardTypeByNumber("6111-1111-1111-1116", "Discover", true)
681+
testCardTypeByNumber("4111-1111-1111-1111", "VISA", true);
682+
testCardTypeByNumber("5111-1111-1111-1118", "MasterCard", true);
683+
testCardTypeByNumber("6111-1111-1111-1116", "Discover", true);
659684
testCardTypeByNumber("3400-0000-0000-009", "AMEX", true);
660685

661-
testCardTypeByNumber("4111-1111-1111-1110", "VISA", false)
662-
testCardTypeByNumber("5432-1111-1111-1111", "MasterCard", false)
663-
testCardTypeByNumber("6611-6611-6611-6611", "Discover", false)
664-
testCardTypeByNumber("3777-7777-7777-7777", "AMEX", false)
665-
686+
testCardTypeByNumber("4111-1111-1111-1110", "VISA", false);
687+
testCardTypeByNumber("5432-1111-1111-1111", "MasterCard", false);
688+
testCardTypeByNumber("6611-6611-6611-6611", "Discover", false);
689+
testCardTypeByNumber("3777-7777-7777-7777", "AMEX", false);
666690
});
667691

668692
test('creditcardtypes, visa', function() {
@@ -677,9 +701,9 @@ test('creditcardtypes, visa', function() {
677701
}
678702
});
679703

680-
testCardTypeByNumber("4111-1111-1111-1111", "VISA", true)
681-
testCardTypeByNumber("5111-1111-1111-1118", "MasterCard", false)
682-
testCardTypeByNumber("6111-1111-1111-1116", "Discover", false)
704+
testCardTypeByNumber("4111-1111-1111-1111", "VISA", true);
705+
testCardTypeByNumber("5111-1111-1111-1118", "MasterCard", false);
706+
testCardTypeByNumber("6111-1111-1111-1116", "Discover", false);
683707
testCardTypeByNumber("3400-0000-0000-009", "AMEX", false);
684708
});
685709

@@ -695,14 +719,14 @@ test('creditcardtypes, mastercard', function() {
695719
}
696720
});
697721

698-
testCardTypeByNumber("5111-1111-1111-1118", "MasterCard", true)
699-
testCardTypeByNumber("6111-1111-1111-1116", "Discover", false)
722+
testCardTypeByNumber("5111-1111-1111-1118", "MasterCard", true);
723+
testCardTypeByNumber("6111-1111-1111-1116", "Discover", false);
700724
testCardTypeByNumber("3400-0000-0000-009", "AMEX", false);
701725
testCardTypeByNumber("4111-1111-1111-1111", "VISA", false);
702726
});
703727

704728
function fillFormWithValuesAndExpect(formSelector, inputValues, expected) {
705-
for (i=0; i < inputValues.length; i++) {
729+
for (var i=0; i < inputValues.length; i++) {
706730
$(formSelector + ' input:eq(' + i + ')').val(inputValues[i]);
707731
}
708732
var actual = $(formSelector).valid();

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test("Constructor", function() {
4040
});
4141

4242
test("validate() without elements, with non-form elements", 0, function() {
43-
$("#doesn-texist").validate();
43+
$("#doesntexist").validate();
4444
});
4545

4646
test("valid() plugin method", function() {

0 commit comments

Comments
 (0)