bklLiudl
2024-07-23 675b8bcc4a3630d95e3d0b97d933e63442075ecb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
(function($) {
 
function methodTest( methodName ) {
    var v = jQuery("#form").validate();
    var method = $.validator.methods[methodName];
    var element = $("#firstname")[0];
    return function(value, param) {
        element.value = value;
        return method.call( v, value, element, param );
    };
}
 
module("methods");
 
test("default messages", function() {
    var m = $.validator.methods;
    $.each(m, function(key) {
        ok( jQuery.validator.messages[key], key + " has a default message." );
    });
});
 
test("digit", function() {
    var method = methodTest("digits");
    ok( method( "123" ), "Valid digits" );
    ok(!method( "123.000" ), "Invalid digits" );
    ok(!method( "123.000,00" ), "Invalid digits" );
    ok(!method( "123.0.0,0" ), "Invalid digits" );
    ok(!method( "x123" ), "Invalid digits" );
    ok(!method( "100.100,0,0" ), "Invalid digits" );
});
 
test("url", function() {
    var method = methodTest("url");
    ok( method( "http://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
    ok( method( "https://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
    ok( method( "ftp://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
    ok( method( "http://www.føtex.dk/" ), "Valid url, danish unicode characters" );
    ok( method( "http://bösendorfer.de/" ), "Valid url, german unicode characters" );
    ok( method( "http://192.168.8.5" ), "Valid IP Address" );
    ok(!method( "http://192.168.8." ), "Invalid IP Address" );
    ok(!method( "http://bassistance" ), "Invalid url" ); // valid
    ok(!method( "http://bassistance." ), "Invalid url" ); // valid
    ok(!method( "http://bassistance,de" ), "Invalid url" );
    ok(!method( "http://bassistance;de" ), "Invalid url" );
    ok(!method( "http://.bassistancede" ), "Invalid url" );
    ok(!method( "bassistance.de" ), "Invalid url" );
});
 
test("url2 (tld optional)", function() {
    var method = methodTest("url2");
    ok( method( "http://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
    ok( method( "https://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
    ok( method( "ftp://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
    ok( method( "http://www.føtex.dk/" ), "Valid url, danish unicode characters" );
    ok( method( "http://bösendorfer.de/" ), "Valid url, german unicode characters" );
    ok( method( "http://192.168.8.5" ), "Valid IP Address" );
    ok(!method( "http://192.168.8." ), "Invalid IP Address" );
    ok( method( "http://bassistance" ), "Invalid url" );
    ok( method( "http://bassistance." ), "Invalid url" );
    ok(!method( "http://bassistance,de" ), "Invalid url" );
    ok(!method( "http://bassistance;de" ), "Invalid url" );
    ok(!method( "http://.bassistancede" ), "Invalid url" );
    ok(!method( "bassistance.de" ), "Invalid url" );
});
 
test("email", function() {
    var method = methodTest("email");
    ok( method( "name@domain.tld" ), "Valid email" );
    ok( method( "name@domain.tl" ), "Valid email" );
    ok( method( "bart+bart@tokbox.com" ), "Valid email" );
    ok( method( "bart+bart@tokbox.travel" ), "Valid email" );
    ok( method( "n@d.tld" ), "Valid email" );
    ok( method( "ole@føtex.dk"), "Valid email" );
    ok( method( "jörn@bassistance.de"), "Valid email" );
    ok( method( "bla.blu@g.mail.com"), "Valid email" );
    ok( method( "\"Scott Gonzalez\"@example.com" ), "Valid email" );
    ok( method( "\"Scott González\"@example.com" ), "Valid email" );
    ok( method( "\"name.\"@domain.tld" ), "Valid email" ); // valid without top label
    ok( method( "\"name,\"@domain.tld" ), "Valid email" ); // valid without top label
    ok( method( "\"name;\"@domain.tld" ), "Valid email" ); // valid without top label
    ok(!method( "name" ), "Invalid email" );
    ok(!method( "name@" ), "Invalid email" );
    ok(!method( "name@domain" ), "Invalid email" );
    ok(!method( "name.@domain.tld" ), "Invalid email" );
    ok(!method( "name,@domain.tld" ), "Invalid email" );
    ok(!method( "name;@domain.tld" ), "Invalid email" );
    ok(!method( "name;@domain.tld." ), "Invalid email" );
});
 
test("email2 (tld optional)", function() {
    var method = methodTest("email2");
    ok( method( "name@domain.tld" ), "Valid email" );
    ok( method( "name@domain.tl" ), "Valid email" );
    ok( method( "bart+bart@tokbox.com" ), "Valid email" );
    ok( method( "bart+bart@tokbox.travel" ), "Valid email" );
    ok( method( "n@d.tld" ), "Valid email" );
    ok( method( "ole@føtex.dk"), "Valid email" );
    ok( method( "jörn@bassistance.de"), "Valid email" );
    ok( method( "bla.blu@g.mail.com"), "Valid email" );
    ok( method( "\"Scott Gonzalez\"@example.com" ), "Valid email" );
    ok( method( "\"Scott González\"@example.com" ), "Valid email" );
    ok( method( "\"name.\"@domain.tld" ), "Valid email" ); // valid without top label
    ok( method( "\"name,\"@domain.tld" ), "Valid email" ); // valid without top label
    ok( method( "\"name;\"@domain.tld" ), "Valid email" ); // valid without top label
    ok(!method( "name" ), "Invalid email" );
    ok(!method( "name@" ), "Invalid email" );
    ok( method( "name@domain" ), "Invalid email" );
    ok(!method( "name.@domain.tld" ), "Invalid email" );
    ok(!method( "name,@domain.tld" ), "Invalid email" );
    ok(!method( "name;@domain.tld" ), "Invalid email" );
});
 
test("number", function() {
    var method = methodTest("number");
    ok( method( "123" ), "Valid number" );
    ok( method( "-123" ), "Valid number" );
    ok( method( "123,000" ), "Valid number" );
    ok( method( "-123,000" ), "Valid number" );
    ok( method( "123,000.00" ), "Valid number" );
    ok( method( "-123,000.00" ), "Valid number" );
    ok(!method( "123.000,00" ), "Invalid number" );
    ok(!method( "123.0.0,0" ), "Invalid number" );
    ok(!method( "x123" ), "Invalid number" );
    ok(!method( "100.100,0,0" ), "Invalid number" );
 
    ok( method( "" ), "Blank is valid" );
    ok( method( "123" ), "Valid decimal" );
    ok( method( "123000" ), "Valid decimal" );
    ok( method( "123000.12" ), "Valid decimal" );
    ok( method( "-123000.12" ), "Valid decimal" );
    ok( method( "123.000" ), "Valid decimal" );
    ok( method( "123,000.00" ), "Valid decimal" );
    ok( method( "-123,000.00" ), "Valid decimal" );
    ok( method( ".100" ), "Valid decimal" );
    ok(!method( "1230,000.00" ), "Invalid decimal" );
    ok(!method( "123.0.0,0" ), "Invalid decimal" );
    ok(!method( "x123" ), "Invalid decimal" );
    ok(!method( "100.100,0,0" ), "Invalid decimal" );
});
 
/* disabled for now, need to figure out how to test localized methods
test("numberDE", function() {
    var method = methodTest("numberDE");
    ok( method( "123" ), "Valid numberDE" );
    ok( method( "-123" ), "Valid numberDE" );
    ok( method( "123.000" ), "Valid numberDE" );
    ok( method( "-123.000" ), "Valid numberDE" );
    ok( method( "123.000,00" ), "Valid numberDE" );
    ok( method( "-123.000,00" ), "Valid numberDE" );
    ok(!method( "123,000.00" ), "Invalid numberDE" );
    ok(!method( "123,0,0.0" ), "Invalid numberDE" );
    ok(!method( "x123" ), "Invalid numberDE" );
    ok(!method( "100,100.0.0" ), "Invalid numberDE" );
 
    ok( method( "" ), "Blank is valid" );
    ok( method( "123" ), "Valid decimalDE" );
    ok( method( "123000" ), "Valid decimalDE" );
    ok( method( "123000,12" ), "Valid decimalDE" );
    ok( method( "-123000,12" ), "Valid decimalDE" );
    ok( method( "123.000" ), "Valid decimalDE" );
    ok( method( "123.000,00" ), "Valid decimalDE" );
    ok( method( "-123.000,00" ), "Valid decimalDE" )
    ok(!method( "123.0.0,0" ), "Invalid decimalDE" );
    ok(!method( "x123" ), "Invalid decimalDE" );
    ok(!method( "100,100.0.0" ), "Invalid decimalDE" );
});
*/
 
test("date", function() {
    var method = methodTest("date");
    ok( method( "06/06/1990" ), "Valid date" );
    ok( method( "6/6/06" ), "Valid date" );
    ok(!method( "1990x-06-06" ), "Invalid date" );
});
 
test("dateISO", function() {
    var method = methodTest("dateISO");
    ok( method( "1990-06-06" ), "Valid date" );
    ok( method( "1990/06/06" ), "Valid date" );
    ok( method( "1990-6-6" ), "Valid date" );
    ok( method( "1990/6/6" ), "Valid date" );
    ok(!method( "1990-106-06" ), "Invalid date" );
    ok(!method( "190-06-06" ), "Invalid date" );
});
 
/* disabled for now, need to figure out how to test localized methods
test("dateDE", function() {
    var method = methodTest("dateDE");
    ok( method( "03.06.1984" ), "Valid dateDE" );
    ok( method( "3.6.84" ), "Valid dateDE" );
    ok(!method( "6-6-06" ), "Invalid dateDE" );
    ok(!method( "1990-06-06" ), "Invalid dateDE" );
    ok(!method( "06/06/1990" ), "Invalid dateDE" );
    ok(!method( "6/6/06" ), "Invalid dateDE" );
});
*/
 
test("required", function() {
    var v = jQuery("#form").validate(),
        method = $.validator.methods.required,
        e = $('#text1, #text1b, #hidden2, #select1, #select2');
    ok( method.call( v, e[0].value, e[0]), "Valid text input" );
    ok(!method.call( v, e[1].value, e[1]), "Invalid text input" );
    ok(!method.call( v, e[1].value, e[2]), "Invalid text input" );
 
    ok(!method.call( v, e[2].value, e[3]), "Invalid select" );
    ok( method.call( v, e[3].value, e[4]), "Valid select" );
 
    e = $('#area1, #area2, #pw1, #pw2');
    ok( method.call( v, e[0].value, e[0]), "Valid textarea" );
    ok(!method.call( v, e[1].value, e[1]), "Invalid textarea" );
    ok( method.call( v, e[2].value, e[2]), "Valid password input" );
    ok(!method.call( v, e[3].value, e[3]), "Invalid password input" );
 
    e = $('#radio1, #radio2, #radio3');
    ok(!method.call( v, e[0].value, e[0]), "Invalid radio" );
    ok( method.call( v, e[1].value, e[1]), "Valid radio" );
    ok( method.call( v, e[2].value, e[2]), "Valid radio" );
 
    e = $('#check1, #check2');
    ok( method.call( v, e[0].value, e[0]), "Valid checkbox" );
    ok(!method.call( v, e[1].value, e[1]), "Invalid checkbox" );
 
    e = $('#select1, #select2, #select3, #select4');
    ok(!method.call( v, e[0].value, e[0]), "Invalid select" );
    ok( method.call( v, e[1].value, e[1]), "Valid select" );
    ok( method.call( v, e[2].value, e[2]), "Valid select" );
    ok( method.call( v, e[3].value, e[3]), "Valid select" );
});
 
test("required with dependencies", function() {
    var v = jQuery("#form").validate(),
        method = $.validator.methods.required,
        e = $('#hidden2, #select1, #area2, #radio1, #check2');
    ok( method.call( v, e[0].value, e[0], "asffsaa"), "Valid text input due to dependency not met" );
    ok(!method.call( v, e[0].value, e[0], "input"), "Invalid text input" );
    ok( method.call( v, e[0].value, e[0], function() { return false; }), "Valid text input due to dependency not met" );
    ok(!method.call( v, e[0].value, e[0], function() { return true; }), "Invalid text input" );
    ok( method.call( v, e[1].value, e[1], "asfsfa"), "Valid select due to dependency not met" );
    ok(!method.call( v, e[1].value, e[1], "input"), "Invalid select" );
    ok( method.call( v, e[2].value, e[2], "asfsafsfa"), "Valid textarea due to dependency not met" );
    ok(!method.call( v, e[2].value, e[2], "input"), "Invalid textarea" );
    ok( method.call( v, e[3].value, e[3], "asfsafsfa"), "Valid radio due to dependency not met" );
    ok(!method.call( v, e[3].value, e[3], "input"), "Invalid radio" );
    ok( method.call( v, e[4].value, e[4], "asfsafsfa"), "Valid checkbox due to dependency not met" );
    ok(!method.call( v, e[4].value, e[4], "input"), "Invalid checkbox" );
});
 
test("minlength", function() {
    var v = jQuery("#form").validate(),
        method = $.validator.methods.minlength,
        param = 2,
        e = $('#text1, #text1c, #text2, #text3');
    ok( method.call( v, e[0].value, e[0], param), "Valid text input" );
    ok(!method.call( v, e[1].value, e[1], param), "Invalid text input" );
    ok(!method.call( v, e[2].value, e[2], param), "Invalid text input" );
    ok( method.call( v, e[3].value, e[3], param), "Valid text input" );
 
    e = $('#check1, #check2, #check3');
    ok(!method.call( v, e[0].value, e[0], param), "Valid checkbox" );
    ok( method.call( v, e[1].value, e[1], param), "Valid checkbox" );
    ok( method.call( v, e[2].value, e[2], param), "Invalid checkbox" );
 
    e = $('#select1, #select2, #select3, #select4, #select5');
    ok(method.call( v, e[0].value, e[0], param), "Valid select " + e[0].id );
    ok(!method.call( v, e[1].value, e[1], param), "Invalid select " + e[1].id );
    ok( method.call( v, e[2].value, e[2], param), "Valid select " + e[2].id );
    ok( method.call( v, e[3].value, e[3], param), "Valid select " + e[3].id );
    ok( method.call( v, e[4].value, e[4], param), "Valid select " + e[4].id );
});
 
test("maxlength", function() {
    var v = jQuery("#form").validate();
    var method = $.validator.methods.maxlength,
        param = 4,
        e = $('#text1, #text2, #text3');
    ok( method.call( v, e[0].value, e[0], param), "Valid text input" );
    ok( method.call( v, e[1].value, e[1], param), "Valid text input" );
    ok(!method.call( v, e[2].value, e[2], param), "Invalid text input" );
 
    e = $('#check1, #check2, #check3');
    ok( method.call( v, e[0].value, e[0], param), "Valid checkbox" );
    ok( method.call( v, e[1].value, e[1], param), "Invalid checkbox" );
    ok(!method.call( v, e[2].value, e[2], param), "Invalid checkbox" );
 
    e = $('#select1, #select2, #select3, #select4');
    ok( method.call( v, e[0].value, e[0], param), "Valid select" );
    ok( method.call( v, e[1].value, e[1], param), "Valid select" );
    ok( method.call( v, e[2].value, e[2], param), "Valid select" );
    ok(!method.call( v, e[3].value, e[3], param), "Invalid select" );
});
 
test("rangelength", function() {
    var v = jQuery("#form").validate();
    var method = $.validator.methods.rangelength,
        param = [2, 4],
        e = $('#text1, #text2, #text3');
    ok( method.call( v, e[0].value, e[0], param), "Valid text input" );
    ok(!method.call( v, e[1].value, e[1], param), "Invalid text input" );
    ok(!method.call( v, e[2].value, e[2], param), "Invalid text input" );
});
 
test("min", function() {
    var v = jQuery("#form").validate();
    var method = $.validator.methods.min,
        param = 8,
        e = $('#value1, #value2, #value3');
    ok(!method.call( v, e[0].value, e[0], param), "Invalid text input" );
    ok( method.call( v, e[1].value, e[1], param), "Valid text input" );
    ok( method.call( v, e[2].value, e[2], param), "Valid text input" );
});
 
test("max", function() {
    var v = jQuery("#form").validate();
    var method = $.validator.methods.max,
        param = 12,
        e = $('#value1, #value2, #value3');
    ok( method.call( v, e[0].value, e[0], param), "Valid text input" );
    ok( method.call( v, e[1].value, e[1], param), "Valid text input" );
    ok(!method.call( v, e[2].value, e[2], param), "Invalid text input" );
});
 
test("range", function() {
    var v = jQuery("#form").validate();
    var method = $.validator.methods.range,
        param = [4,12],
        e = $('#value1, #value2, #value3');
    ok(!method.call( v, e[0].value, e[0], param), "Invalid text input" );
    ok( method.call( v, e[1].value, e[1], param), "Valid text input" );
    ok(!method.call( v, e[2].value, e[2], param), "Invalid text input" );
});
 
test("equalTo", function() {
    var v = jQuery("#form").validate();
    var method = $.validator.methods.equalTo,
        e = $('#text1, #text2');
    ok( method.call( v, "Test", e[0], "#text1"), "Text input" );
    ok( method.call( v, "T", e[1], "#text2"), "Another one" );
});
 
test("creditcard", function() {
    var method = methodTest("creditcard");
    ok( method( "446-667-651" ), "Valid creditcard number" );
    ok( method( "446 667 651" ), "Valid creditcard number" );
    ok( !method( "asdf" ), "Invalid creditcard number" );
});
 
test("extension", function() {
    var method = methodTest("extension");
    ok( method( "picture.gif" ), "Valid default accept type" );
    ok( method( "picture.jpg" ), "Valid default accept type" );
    ok( method( "picture.jpeg" ), "Valid default accept type" );
    ok( method( "picture.png" ), "Valid default accept type" );
    ok( !method( "picture.pgn" ), "Invalid default accept type" );
 
    var v = jQuery("#form").validate();
    method = function(value, param) {
        return $.validator.methods.extension.call(v, value, $('#text1')[0], param);
    };
    ok( method( "picture.doc", "doc"), "Valid custom accept type" );
    ok( method( "picture.pdf", "doc|pdf"), "Valid custom accept type" );
    ok( method( "picture.pdf", "pdf|doc"), "Valid custom accept type" );
    ok( !method( "picture.pdf", "doc"), "Invalid custom accept type" );
    ok( !method( "picture.doc", "pdf"), "Invalid custom accept type" );
 
    ok( method( "picture.pdf", "doc,pdf"), "Valid custom accept type, comma seperated" );
    ok( method( "picture.pdf", "pdf,doc"), "Valid custom accept type, comma seperated" );
    ok( !method( "picture.pdf", "gop,top"), "Invalid custom accept type, comma seperated" );
});
 
test("remote", function() {
    expect(7);
    stop();
    var e = $("#username");
    var v = $("#userForm").validate({
        rules: {
            username: {
                required: true,
                remote: "users.php"
            }
        },
        messages: {
            username: {
                required: "Please",
                remote: jQuery.validator.format("{0} in use")
            }
        },
        submitHandler: function() {
            ok( false, "submitHandler may never be called when validating only elements");
        }
    });
    $(document).ajaxStop(function() {
        $(document).unbind("ajaxStop");
        equal( 1, v.size(), "There must be one error" );
        equal( "Peter in use", v.errorList[0].message );
 
        $(document).ajaxStop(function() {
            $(document).unbind("ajaxStop");
            equal( 1, v.size(), "There must be one error" );
            equal( "Peter2 in use", v.errorList[0].message );
            start();
        });
        e.val("Peter2");
        strictEqual( v.element(e), true, "new value, new request; dependency-mismatch considered as valid though" );
    });
    strictEqual( v.element(e), false, "invalid element, nothing entered yet" );
    e.val("Peter");
    strictEqual( v.element(e), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" );
});
 
test("remote, customized ajax options", function() {
    expect(2);
    stop();
    var v = $("#userForm").validate({
        rules: {
            username: {
                required: true,
                remote: {
                    url: "users.php",
                    type: "POST",
                    beforeSend: function(request, settings) {
                        deepEqual(settings.type, "POST");
                        deepEqual(settings.data, "username=asdf&email=email.com");
                    },
                    data: {
                        email: function() {
                            return "email.com";
                        }
                    },
                    complete: function() {
                        start();
                    }
                }
            }
        }
    });
    $("#username").val("asdf");
    $("#userForm").valid();
});
 
 
test("remote extensions", function() {
    expect(5);
    stop();
    var e = $("#username");
    var v = $("#userForm").validate({
        rules: {
            username: {
                required: true,
                remote: "users2.php"
            }
        },
        messages: {
            username: {
                required: "Please"
            }
        },
        submitHandler: function() {
            ok( false, "submitHandler may never be called when validating only elements");
        }
    });
    $(document).ajaxStop(function() {
        $(document).unbind("ajaxStop");
        equal( 1, v.size(), "There must be one error" );
        equal( v.errorList[0].message, "asdf is already taken, please try something else" );
        v.element(e);
        equal( v.errorList[0].message, "asdf is already taken, please try something else", "message doesn't change on revalidation" );
        start();
    });
    strictEqual( v.element(e), false, "invalid element, nothing entered yet" );
    e.val("asdf");
    strictEqual( v.element(e), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" );
});
 
test("remote radio correct value sent", function() {
    expect(1);
    stop();
    var e = $("#testForm10Radio2");
    e.attr('checked', 'checked');
    var v = $("#testForm10").validate({
        rules: {
            testForm10Radio: {
                required: true,
                remote: {
                    url: "echo.php",
                    dataType: "json",
                    success: function(data) {
                        equal( data['testForm10Radio'], '2', ' correct radio value sent' );
                        start();
                    }
                }
            }
        }
    });
 
    v.element(e);
});
 
test("remote reset clear old value", function() {
    expect(1);
    stop();
    var e = $("#username");
    var v = $("#userForm").validate({
        rules: {
            username: {
                required: true,
                remote: {
                    url: "echo.php",
                    dataFilter: function(data) {
                        var json = JSON.parse(data);
                        if(json.username === 'asdf') {
                            return "\"asdf is already taken\"";
                        }
                        return "\"" + true + "\"";
                    }
                }
            }
        }
    });
    $(document).ajaxStop(function() {
        var waitTimeout;
 
        $(document).unbind("ajaxStop");
 
 
        $(document).ajaxStop(function() {
            clearTimeout(waitTimeout);
            ok( true, "Remote request sent to server" );
            start();
        });
 
 
        v.resetForm();
        e.val("asdf");
        waitTimeout = setTimeout(function() {
            ok( false, "Remote server did not get request");
            start();
        }, 200);
        v.element(e);
    });
    e.val("asdf");
    v.element(e);
});
 
module("additional methods");
 
test("phone (us)", function() {
    var method = methodTest("phoneUS");
    ok( method( "1(212)-999-2345" ), "Valid us phone number" );
    ok( method( "212 999 2344" ), "Valid us phone number" );
    ok( method( "212-999-0983" ), "Valid us phone number" );
    ok(!method( "111-123-5434" ), "Invalid us phone number" );
    ok(!method( "212 123 4567" ), "Invalid us phone number" );
});
 
test("mobileUK", function() {
    var method = methodTest("mobileUK");
    ok( method( "07734234323" ), "Valid UK Mobile Number" );
    ok( method( "+447734234323" ), "Valid UK Mobile Number" );
    ok( !method( "07034234323" ), "Invalid UK Mobile Number" );
    ok( !method( "0753423432" ), "Invalid UK Mobile Number" );
    ok( !method( "07604234323" ), "Invalid UK Mobile Number" );
    ok( !method( "077342343234" ), "Invalid UK Mobile Number" );
    ok( !method( "044342343234" ), "Invalid UK Mobile Number" );
    ok( !method( "+44753423432" ), "Invalid UK Mobile Number" );
    ok( !method( "+447604234323" ), "Invalid UK Mobile Number" );
    ok( !method( "+4477342343234" ), "Invalid UK Mobile Number" );
    ok( !method( "+4444342343234" ), "Invalid UK Mobile Number" );
});
 
test("dateITA", function() {
    var method = methodTest("dateITA");
    ok( method( "01/01/1900" ), "Valid date ITA" );
    ok(!method( "01/13/1990" ), "Invalid date ITA" );
    ok(!method( "01.01.1900" ), "Invalid date ITA" );
    ok(!method( "01/01/199" ), "Invalid date ITA" );
});
 
test("dateNL", function() {
    var method = methodTest("dateNL");
    ok( method( "01-01-1900" ), "Valid date NL" );
    ok( method( "01.01.1900" ), "Valid date NL" );
    ok( method( "01/01/1900" ), "Valid date NL" );
    ok( method( "01-01-00" ), "Valid date NL" );
    ok( method( "1-01-1900" ), "Valid date NL" );
    ok( method( "10-10-1900" ), "Valid date NL" );
    ok(!method( "0-01-1900" ), "Invalid date NL" );
    ok(!method( "00-01-1900" ), "Invalid date NL" );
    ok(!method( "35-01-1990" ), "Invalid date NL" );
    ok(!method( "01.01.190" ), "Invalid date NL" );
});
 
test("time", function() {
    var method = methodTest("time");
    ok( method("00:00"), "Valid time, lower bound" );
    ok( method("23:59"), "Valid time, upper bound" );
    ok( !method("12"), "Invalid time" );
    ok( !method("00:60"), "Invalid time" );
    ok( !method("24:60"), "Invalid time" );
    ok( !method("24:00"), "Invalid time" );
    ok( !method("29:59"), "Invalid time" );
    ok( !method("30:00"), "Invalid time" );
    ok( !method("120:00"), "Invalid time" );
    ok( !method("12:001"), "Invalid time" );
    ok( !method("12:00a"), "Invalid time" );
});
 
test("time12h", function() {
    var method = methodTest("time12h");
    ok( method("12:00 AM"), "Valid time, lower bound, am" );
    ok( method("11:59 AM"), "Valid time, upper bound, am" );
    ok( method("12:00AM"), "Valid time, no space, am" );
    ok( method("12:00PM"), "Valid time, no space, pm" );
    ok( method("12:00 PM"), "Valid time, lower bound, pm" );
    ok( method("11:59 PM"), "Valid time, upper bound, pm" );
    ok( method("11:59 am"), "Valid time, also accept lowercase" );
    ok( method("11:59 pm"), "Valid time, also accept lowercase" );
    ok( method("1:59 pm"), "Valid time, single hour, no leading 0" );
    ok( method("01:59 pm"), "Valid time, single hour, leading 0" );
    ok( !method("12:00"), "Invalid time" );
    ok( !method("9"), "Invalid time" );
    ok( !method("9 am"), "Invalid time" );
    ok( !method("12:61 am"), "Invalid time" );
    ok( !method("13:00 am"), "Invalid time" );
    ok( !method("00:00 am"), "Invalid time" );
});
 
test("minWords", function() {
    var method = methodTest("minWords");
    ok( method("hello worlds", 2), "plain text, valid" );
    ok( method("<em>hello</em> world", 2), "html, valid" );
    ok( !method("hello", 2), "plain text, invalid" );
    ok( !method("<em>world</em>", 2), "html, invalid" );
    ok( !method("world <br/>", 2), "html, invalid" );
});
 
test("maxWords", function() {
    var method = methodTest("maxWords");
    ok( method("hello", 2), "plain text, valid" );
    ok( method("<em>world</em>", 2), "html, valid" );
    ok( method("world <br/>", 2), "html, valid" );
    ok( method("hello worlds", 2), "plain text, valid" );
    ok( method("<em>hello</em> world", 2), "html, valid" );
    ok( !method("hello 123 world", 2), "plain text, invalid" );
    ok( !method("<em>hello</em> 123 world", 2), "html, invalid" );
});
 
test("rangeWords", function() {
    var method = methodTest("rangeWords");
    ok( method("hello", [0, 2]), "plain text, valid" );
    ok( method("hello worlds", [0, 2]), "plain text, valid" );
    ok( method("<em>hello</em> world", [0, 2]), "html, valid" );
    ok( !method("hello worlds what is up", [0, 2]), "plain text, invalid" );
    ok( !method("<em>Hello</em> <em>world</em> <em>hello</em>", [0, 2]), "html, invalid" );
});
 
test("pattern", function() {
    var method = methodTest("pattern");
    ok( method( "AR1004", "AR\\d{4}" ), "Correct format for the given RegExp" );
    ok( method( "AR1004", /^AR\d{4}$/ ), "Correct format for the given RegExp" );
    ok( !method( "BR1004", /^AR\d{4}$/ ), "Invalid format for the given RegExp" );
});
 
function testCardTypeByNumber(number, cardname, expected) {
    $("#cardnumber").val(number);
    var actual = $("#ccform").valid();
    equal(actual, expected, $.format("Expect card number {0} to validate to {1}, actually validated to ", number, expected));
}
 
test('creditcardtypes, all', function() {
    $("#ccform").validate({
        rules: {
            cardnumber: {
                creditcard: true,
                creditcardtypes: {
                    all: true
                }
            }
        }
    });
 
    testCardTypeByNumber("4111-1111-1111-1111", "VISA", true);
    testCardTypeByNumber("5111-1111-1111-1118", "MasterCard", true);
    testCardTypeByNumber("6111-1111-1111-1116", "Discover", true);
    testCardTypeByNumber("3400-0000-0000-009", "AMEX", true);
 
    testCardTypeByNumber("4111-1111-1111-1110", "VISA", false);
    testCardTypeByNumber("5432-1111-1111-1111", "MasterCard", false);
    testCardTypeByNumber("6611-6611-6611-6611", "Discover", false);
    testCardTypeByNumber("3777-7777-7777-7777", "AMEX", false);
});
 
test('creditcardtypes, visa', function() {
    $("#ccform").validate({
        rules: {
            cardnumber: {
                creditcard: true,
                creditcardtypes: {
                    visa: true
                }
            }
        }
    });
 
    testCardTypeByNumber("4111-1111-1111-1111", "VISA", true);
    testCardTypeByNumber("5111-1111-1111-1118", "MasterCard", false);
    testCardTypeByNumber("6111-1111-1111-1116", "Discover", false);
    testCardTypeByNumber("3400-0000-0000-009", "AMEX", false);
});
 
test('creditcardtypes, mastercard', function() {
    $("#ccform").validate({
        rules: {
            cardnumber: {
                creditcard: true,
                creditcardtypes: {
                    mastercard: true
                }
            }
        }
    });
 
    testCardTypeByNumber("5111-1111-1111-1118", "MasterCard", true);
    testCardTypeByNumber("6111-1111-1111-1116", "Discover", false);
    testCardTypeByNumber("3400-0000-0000-009", "AMEX", false);
    testCardTypeByNumber("4111-1111-1111-1111", "VISA", false);
});
 
function fillFormWithValuesAndExpect(formSelector, inputValues, expected) {
    for (var i=0; i < inputValues.length; i++) {
        $(formSelector + ' input:eq(' + i + ')').val(inputValues[i]);
    }
    var actual = $(formSelector).valid();
    equal(actual, expected, $.format("Filled inputs of form '{0}' with {1} values ({2})", formSelector, inputValues.length, inputValues.toString()));
 
}
 
test('require_from_group', function() {
    $("#productInfo").validate({
        rules: {
            partnumber:  {require_from_group: [2,".productInfo"]},
            description: {require_from_group: [2,".productInfo"]},
            discount: {require_from_group: [2,".productInfo"]}
        }
    });
 
    fillFormWithValuesAndExpect('#productInfo', [], false);
    fillFormWithValuesAndExpect('#productInfo', [123], false);
    $('#productInfo input[type="checkbox"]').attr('checked', 'checked');
    fillFormWithValuesAndExpect('#productInfo', [123], true);
    $('#productInfo input[type="checkbox"]').removeAttr('checked');
    fillFormWithValuesAndExpect('#productInfo', [123, 'widget'], true);
    fillFormWithValuesAndExpect('#productInfo', [123, 'widget', 'red'], true);
    fillFormWithValuesAndExpect('#productInfo', [123, 'widget', 'red'], true);
});
 
test('skip_or_fill_minimum', function() {
    $("#productInfo").validate({
        rules: {
            partnumber:  {skip_or_fill_minimum: [2,".productInfo"]},
            description: {skip_or_fill_minimum: [2,".productInfo"]},
            color:       {skip_or_fill_minimum: [2,".productInfo"]}
        }
    });
 
    fillFormWithValuesAndExpect('#productInfo', [], true);
    fillFormWithValuesAndExpect('#productInfo', [123], false);
    fillFormWithValuesAndExpect('#productInfo', [123, 'widget'], true);
    fillFormWithValuesAndExpect('#productInfo', [123, 'widget', 'red'], true);
});
 
test("zipcodeUS", function() {
    var method = methodTest("zipcodeUS");
    ok( method( "12345" ), "Valid zip" );
    ok( method( "12345-2345" ), "Valid zip" );
    ok(!method( "1" ), "Invalid zip" );
    ok(!method( "1234" ), "Invalid zip" );
    ok(!method( "123-23" ), "Invalid zip" );
    ok(!method( "12345-43" ), "Invalid zip" );
});
 
})(jQuery);