Subversion-Projekte lars-tiefland.zeldi.de_alt

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2 lars 1
function methodTest( methodName ) {
2
	var v = jQuery( "#form" ).validate(),
3
		method = $.validator.methods[ methodName ],
4
		element = $( "#firstname" )[ 0 ];
5
 
6
	return function( value, param ) {
7
		element.value = value;
8
		return method.call( v, value, element, param );
9
	};
10
}
11
 
12
/**
13
 * Creates a dummy DOM file input with FileList
14
 * @param filename
15
 * @param mimeType
16
 * @returns {{}}
17
 */
18
function acceptFileDummyInput( filename, mimeType ) {
19
 
20
	function dummy() {
21
		return file;
22
	}
23
 
24
	// https://developer.mozilla.org/en-US/docs/Web/API/FileList
25
	var file = {
26
			name: filename,
27
			size: 500001,
28
			type: mimeType
29
		},
30
		fileList = {
31
			0: file,
32
			length: 1,
33
			item: dummy
34
		};
35
 
36
	return {
37
		type: "file",
38
		files: fileList,
39
		nodeName: "INPUT",
40
		value: "/tmp/fake_value",
41
		hasAttribute: function() { return false; }
42
	};
43
}
44
 
45
function fileDummyInput( selectedFiles ) {
46
	var aFiles = [],
47
		oFiles;
48
 
49
	for ( var i = 0; i < selectedFiles.length; i++ ) {
50
		aFiles.push( {
51
			name: selectedFiles[ i ].name,
52
			size: selectedFiles[ i ].size,
53
			type: "image/jpeg"
54
		} );
55
	}
56
 
57
	//Convert the array of objects to an object.
58
	oFiles = aFiles.reduce( function( acc, cur, i ) {
59
		acc[ i ] = cur;
60
		return acc;
61
	}, {} );
62
 
63
	//Add the "length" property to the object.
64
	oFiles.length = selectedFiles.length;
65
 
66
	//Add the "item()" method to the object.
67
	oFiles.item = function( i ) { return aFiles[ i ]; };
68
 
69
	return {
70
		type: "file",
71
		files: oFiles,
72
		nodeName: "INPUT",
73
		value: "/tmp/fake_value",
74
		hasAttribute: function() { return false; }
75
	};
76
}
77
 
78
QUnit.module( "methods" );
79
 
80
QUnit.test( "default messages", function( assert ) {
81
	var m = $.validator.methods;
82
	$.each( m, function( key ) {
83
		assert.ok( jQuery.validator.messages[ key ], key + " has a default message." );
84
	} );
85
} );
86
 
87
QUnit.test( "digit", function( assert ) {
88
	var method = methodTest( "digits" );
89
	assert.ok( method( "123" ), "Valid digits" );
90
	assert.ok( !method( "123.000" ), "Invalid digits" );
91
	assert.ok( !method( "123.000,00" ), "Invalid digits" );
92
	assert.ok( !method( "123.0.0,0" ), "Invalid digits" );
93
	assert.ok( !method( "x123" ), "Invalid digits" );
94
	assert.ok( !method( "100.100,0,0" ), "Invalid digits" );
95
} );
96
 
97
QUnit.test( "url", function( assert ) {
98
	var method = methodTest( "url" );
99
	assert.ok( method( "http://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
100
	assert.ok( method( "https://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
101
	assert.ok( method( "ftp://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
102
	assert.ok( method( "http://www.føtex.dk/" ), "Valid url, danish unicode characters" );
103
	assert.ok( method( "http://bösendorfer.de/" ), "Valid url, german unicode characters" );
104
	assert.ok( method( "http://142.42.1.1" ), "Valid IP Address" );
105
	assert.ok( method( "http://pro.photography" ), "Valid long TLD" );
106
	assert.ok( method( "//code.jquery.com/jquery-1.11.3.min.js" ), "Valid protocol-relative url" );
107
	assert.ok( method( "//142.42.1.1" ), "Valid protocol-relative IP Address" );
108
	assert.ok( !method( "htp://code.jquery.com/jquery-1.11.3.min.js" ), "Invalid protocol" );
109
	assert.ok( !method( "http://192.168.8." ), "Invalid IP Address" );
110
	assert.ok( !method( "http://bassistance" ), "Invalid url" ); // Valid
111
	assert.ok( !method( "http://bassistance." ), "Invalid url" ); // Valid
112
	assert.ok( !method( "http://bassistance,de" ), "Invalid url" );
113
	assert.ok( !method( "http://bassistance;de" ), "Invalid url" );
114
	assert.ok( !method( "http://.bassistancede" ), "Invalid url" );
115
	assert.ok( !method( "bassistance.de" ), "Invalid url" );
116
} );
117
 
118
QUnit.test( "url2 (tld optional)", function( assert ) {
119
	var method = methodTest( "url2" );
120
	assert.ok( method( "http://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
121
	assert.ok( method( "https://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
122
	assert.ok( method( "ftp://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );
123
	assert.ok( method( "http://www.føtex.dk/" ), "Valid url, danish unicode characters" );
124
	assert.ok( method( "http://bösendorfer.de/" ), "Valid url, german unicode characters" );
125
	assert.ok( method( "http://192.168.8.5" ), "Valid IP Address" );
126
	assert.ok( !method( "http://192.168.8." ), "Invalid IP Address" );
127
	assert.ok( method( "http://bassistance" ), "Invalid url" );
128
	assert.ok( method( "http://bassistance." ), "Invalid url" );
129
	assert.ok( !method( "http://bassistance,de" ), "Invalid url" );
130
	assert.ok( !method( "http://bassistance;de" ), "Invalid url" );
131
	assert.ok( !method( "http://.bassistancede" ), "Invalid url" );
132
	assert.ok( !method( "bassistance.de" ), "Invalid url" );
133
} );
134
 
135
QUnit.test( "email", function( assert ) {
136
	var method = methodTest( "email" );
137
	assert.ok( method( "name@domain.tld" ), "Valid email" );
138
	assert.ok( method( "name@domain.tl" ), "Valid email" );
139
	assert.ok( method( "bart+bart@tokbox.com" ), "Valid email" );
140
	assert.ok( method( "bart+bart@tokbox.travel" ), "Valid email" );
141
	assert.ok( method( "n@d.tld" ), "Valid email" );
142
	assert.ok( method( "bla.blu@g.mail.com" ), "Valid email" );
143
	assert.ok( method( "name@domain" ), "Valid email" );
144
	assert.ok( method( "name.@domain.tld" ), "Valid email" );
145
	assert.ok( method( "name@website.a" ), "Valid email" );
146
	assert.ok( method( "name@pro.photography" ), "Valid email" );
147
	assert.ok( !method( "ole@føtex.dk" ), "Invalid email" );
148
	assert.ok( !method( "jörn@bassistance.de" ), "Invalid email" );
149
	assert.ok( !method( "name" ), "Invalid email" );
150
	assert.ok( !method( "test@test-.com" ), "Invalid email" );
151
	assert.ok( !method( "name@" ), "Invalid email" );
152
	assert.ok( !method( "name,@domain.tld" ), "Invalid email" );
153
	assert.ok( !method( "name;@domain.tld" ), "Invalid email" );
154
	assert.ok( !method( "name;@domain.tld." ), "Invalid email" );
155
} );
156
 
157
QUnit.test( "number", function( assert ) {
158
	var method = methodTest( "number" );
159
	assert.ok( method( "123" ), "Valid number" );
160
	assert.ok( method( "-123" ), "Valid number" );
161
	assert.ok( method( "123,000" ), "Valid number" );
162
	assert.ok( method( "-123,000" ), "Valid number" );
163
	assert.ok( method( "123,000.00" ), "Valid number" );
164
	assert.ok( method( "-123,000.00" ), "Valid number" );
165
	assert.ok( !method( "-" ), "Invalid number" );
166
	assert.ok( !method( "123.000,00" ), "Invalid number" );
167
	assert.ok( !method( "123.0.0,0" ), "Invalid number" );
168
	assert.ok( !method( "x123" ), "Invalid number" );
169
	assert.ok( !method( "100.100,0,0" ), "Invalid number" );
170
 
171
	assert.ok( method( "" ), "Blank is valid" );
172
	assert.ok( method( "123" ), "Valid decimal" );
173
	assert.ok( method( "123000" ), "Valid decimal" );
174
	assert.ok( method( "123000.12" ), "Valid decimal" );
175
	assert.ok( method( "-123000.12" ), "Valid decimal" );
176
	assert.ok( method( "123.000" ), "Valid decimal" );
177
	assert.ok( method( "123,000.00" ), "Valid decimal" );
178
	assert.ok( method( "-123,000.00" ), "Valid decimal" );
179
	assert.ok( method( ".100" ), "Valid decimal" );
180
	assert.ok( !method( "1230,000.00" ), "Invalid decimal" );
181
	assert.ok( !method( "123.0.0,0" ), "Invalid decimal" );
182
	assert.ok( !method( "x123" ), "Invalid decimal" );
183
	assert.ok( !method( "100.100,0,0" ), "Invalid decimal" );
184
} );
185
 
186
/* Disabled for now, need to figure out how to test localized methods
187
QUnit.test("numberDE", function( assert ) {
188
	var method = methodTest("numberDE");
189
	assert.ok( method( "123" ), "Valid numberDE" );
190
	assert.ok( method( "-123" ), "Valid numberDE" );
191
	assert.ok( method( "123.000" ), "Valid numberDE" );
192
	assert.ok( method( "-123.000" ), "Valid numberDE" );
193
	assert.ok( method( "123.000,00" ), "Valid numberDE" );
194
	assert.ok( method( "-123.000,00" ), "Valid numberDE" );
195
	assert.ok(!method( "123,000.00" ), "Invalid numberDE" );
196
	assert.ok(!method( "123,0,0.0" ), "Invalid numberDE" );
197
	assert.ok(!method( "x123" ), "Invalid numberDE" );
198
	assert.ok(!method( "100,100.0.0" ), "Invalid numberDE" );
199
 
200
	assert.ok( method( "" ), "Blank is valid" );
201
	assert.ok( method( "123" ), "Valid decimalDE" );
202
	assert.ok( method( "123000" ), "Valid decimalDE" );
203
	assert.ok( method( "123000,12" ), "Valid decimalDE" );
204
	assert.ok( method( "-123000,12" ), "Valid decimalDE" );
205
	assert.ok( method( "123.000" ), "Valid decimalDE" );
206
	assert.ok( method( "123.000,00" ), "Valid decimalDE" );
207
	assert.ok( method( "-123.000,00" ), "Valid decimalDE" )
208
	assert.ok(!method( "123.0.0,0" ), "Invalid decimalDE" );
209
	assert.ok(!method( "x123" ), "Invalid decimalDE" );
210
	assert.ok(!method( "100,100.0.0" ), "Invalid decimalDE" );
211
});
212
*/
213
 
214
QUnit.test( "date", function( assert ) {
215
	var method = methodTest( "date" );
216
	assert.ok( method( "06/06/1990" ), "Valid date" );
217
	assert.ok( method( "6/6/06" ), "Valid date" );
218
	assert.ok( !method( "1990x-06-06" ), "Invalid date" );
219
} );
220
 
221
QUnit.test( "dateISO", function( assert ) {
222
	var method = methodTest( "dateISO" );
223
	assert.ok( method( "1990-06-06" ), "Valid date" );
224
	assert.ok( method( "1990-01-01" ), "Valid date" );
225
	assert.ok( method( "1990-01-31" ), "Valid date" );
226
	assert.ok( method( "1990-12-01" ), "Valid date" );
227
	assert.ok( method( "1990-12-31" ), "Valid date" );
228
	assert.ok( method( "1990/06/06" ), "Valid date" );
229
	assert.ok( method( "1990-6-6" ), "Valid date" );
230
	assert.ok( method( "1990/6/6" ), "Valid date" );
231
	assert.ok( !method( "1990-106-06" ), "Invalid date" );
232
	assert.ok( !method( "190-06-06" ), "Invalid date" );
233
	assert.ok( !method( "1990-00-06" ), "Invalid date" );
234
	assert.ok( !method( "1990-13-01" ), "Invalid date" );
235
	assert.ok( !method( "1990-01-00" ), "Invalid date" );
236
	assert.ok( !method( "1990-01-32" ), "Invalid date" );
237
	assert.ok( !method( "1990-13-32" ), "Invalid date" );
238
} );
239
 
240
/* Disabled for now, need to figure out how to test localized methods
241
QUnit.test("dateDE", function( assert ) {
242
	var method = methodTest("dateDE");
243
	assert.ok( method( "03.06.1984" ), "Valid dateDE" );
244
	assert.ok( method( "3.6.84" ), "Valid dateDE" );
245
	assert.ok(!method( "6-6-06" ), "Invalid dateDE" );
246
	assert.ok(!method( "1990-06-06" ), "Invalid dateDE" );
247
	assert.ok(!method( "06/06/1990" ), "Invalid dateDE" );
248
	assert.ok(!method( "6/6/06" ), "Invalid dateDE" );
249
});
250
*/
251
 
252
QUnit.test( "required", function( assert ) {
253
	var v = jQuery( "#form" ).validate(),
254
		method = $.validator.methods.required,
255
		e = $( "#text1, #text1b, #hidden2, #select1, #select2" );
256
	assert.ok( method.call( v, e[ 0 ].value, e[ 0 ] ), "Valid text input" );
257
	assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ] ), "Invalid text input" );
258
	assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ] ), "Invalid text input" );
259
 
260
	assert.ok( !method.call( v, e[ 3 ].value, e[ 3 ] ), "Invalid select" );
261
	assert.ok( method.call( v, e[ 4 ].value, e[ 4 ] ), "Valid select" );
262
 
263
	e = $( "#area1, #area2, #pw1, #pw2" );
264
	assert.ok( method.call( v, e[ 0 ].value, e[ 0 ] ), "Valid textarea" );
265
	assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ] ), "Invalid textarea" );
266
	assert.ok( method.call( v, e[ 2 ].value, e[ 2 ] ), "Valid password input" );
267
	assert.ok( !method.call( v, e[ 3 ].value, e[ 3 ] ), "Invalid password input" );
268
 
269
	e = $( "#radio1, #radio2, #radio3" );
270
	assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ] ), "Invalid radio" );
271
	assert.ok( method.call( v, e[ 1 ].value, e[ 1 ] ), "Valid radio" );
272
	assert.ok( method.call( v, e[ 2 ].value, e[ 2 ] ), "Valid radio" );
273
 
274
	e = $( "#check1, #check2" );
275
	assert.ok( method.call( v, e[ 0 ].value, e[ 0 ] ), "Valid checkbox" );
276
	assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ] ), "Invalid checkbox" );
277
 
278
	e = $( "#select1, #select2, #select3, #select4" );
279
	assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ] ), "Invalid select" );
280
	assert.ok( method.call( v, e[ 1 ].value, e[ 1 ] ), "Valid select" );
281
	assert.ok( method.call( v, e[ 2 ].value, e[ 2 ] ), "Valid select" );
282
	assert.ok( method.call( v, e[ 3 ].value, e[ 3 ] ), "Valid select" );
283
} );
284
 
285
QUnit.test( "required with dependencies", function( assert ) {
286
	var v = jQuery( "#form" ).validate(),
287
		method = $.validator.methods.required,
288
		e = $( "#hidden2, #select1, #area2, #radio1, #check2" );
289
	assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], "asffsaa" ), "Valid text input due to dependency not met" );
290
	assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ], "input" ), "Invalid text input" );
291
	assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], function() { return false; } ), "Valid text input due to dependency not met" );
292
	assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ], function() { return true; } ), "Invalid text input" );
293
	assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], "asfsfa" ), "Valid select due to dependency not met" );
294
	assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ], "input" ), "Invalid select" );
295
	assert.ok( method.call( v, e[ 2 ].value, e[ 2 ], "asfsafsfa" ), "Valid textarea due to dependency not met" );
296
	assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], "input" ), "Invalid textarea" );
297
	assert.ok( method.call( v, e[ 3 ].value, e[ 3 ], "asfsafsfa" ), "Valid radio due to dependency not met" );
298
	assert.ok( !method.call( v, e[ 3 ].value, e[ 3 ], "input" ), "Invalid radio" );
299
	assert.ok( method.call( v, e[ 4 ].value, e[ 4 ], "asfsafsfa" ), "Valid checkbox due to dependency not met" );
300
	assert.ok( !method.call( v, e[ 4 ].value, e[ 4 ], "input" ), "Invalid checkbox" );
301
} );
302
 
303
QUnit.test( "minlength", function( assert ) {
304
	var v = jQuery( "#form" ).validate(),
305
		method = $.validator.methods.minlength,
306
		param = 2,
307
		e = $( "#text1, #text1c, #text2, #text3" );
308
	assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" );
309
	assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" );
310
	assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" );
311
	assert.ok( method.call( v, e[ 3 ].value, e[ 3 ], param ), "Valid text input" );
312
 
313
	e = $( "#check1, #check2, #check3" );
314
	assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid checkbox" );
315
	assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid checkbox" );
316
	assert.ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid checkbox" );
317
 
318
	e = $( "#select1, #select2, #select3, #select4, #select5" );
319
	assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid select " + e[ 0 ].id );
320
	assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ], param ), "Invalid select " + e[ 1 ].id );
321
	assert.ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Valid select " + e[ 2 ].id );
322
	assert.ok( method.call( v, e[ 3 ].value, e[ 3 ], param ), "Valid select " + e[ 3 ].id );
323
	assert.ok( method.call( v, e[ 4 ].value, e[ 4 ], param ), "Valid select " + e[ 4 ].id );
324
} );
325
 
326
QUnit.test( "maxlength", function( assert ) {
327
	var v = jQuery( "#form" ).validate(),
328
		method = $.validator.methods.maxlength,
329
		param = 4,
330
		e = $( "#text1, #text2, #text3" );
331
 
332
	assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" );
333
	assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" );
334
	assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" );
335
 
336
	e = $( "#check1, #check2, #check3" );
337
	assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid checkbox" );
338
	assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Invalid checkbox" );
339
	assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid checkbox" );
340
 
341
	e = $( "#select1, #select2, #select3, #select4" );
342
	assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid select" );
343
	assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid select" );
344
	assert.ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Valid select" );
345
	assert.ok( !method.call( v, e[ 3 ].value, e[ 3 ], param ), "Invalid select" );
346
} );
347
 
348
QUnit.test( "rangelength", function( assert ) {
349
	var v = jQuery( "#form" ).validate(),
350
		method = $.validator.methods.rangelength,
351
		param = [ 2, 4 ],
352
		e = $( "#text1, #text2, #text3" );
353
 
354
	assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" );
355
	assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ], param ), "Invalid text input" );
356
	assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" );
357
} );
358
 
359
QUnit.test( "min", function( assert ) {
360
	var v = jQuery( "#form" ).validate(),
361
		method = $.validator.methods.min,
362
		param = 8,
363
		e = $( "#value1, #value2, #value3" );
364
 
365
	assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ], param ), "Invalid text input" );
366
	assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" );
367
	assert.ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Valid text input" );
368
} );
369
 
370
QUnit.test( "max", function( assert ) {
371
	var v = jQuery( "#form" ).validate(),
372
		method = $.validator.methods.max,
373
		param = 12,
374
		e = $( "#value1, #value2, #value3" );
375
 
376
	assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" );
377
	assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" );
378
	assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" );
379
} );
380
 
381
QUnit.test( "range", function( assert ) {
382
	var v = jQuery( "#form" ).validate(),
383
		method = $.validator.methods.range,
384
		param = [ 4, 12 ],
385
		e = $( "#value1, #value2, #value3" );
386
 
387
	assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ], param ), "Invalid text input" );
388
	assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" );
389
	assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" );
390
} );
391
 
392
QUnit.test( "step", function( assert ) {
393
	var v = jQuery( "#form" ).validate(),
394
		method = $.validator.methods.step,
395
		param = 1000,
396
		e = $( "#value1, #value2, #value3, #value4" );
397
 
398
	assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" );
399
	assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ], param ), "Invalid text input" );
400
	assert.ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Valid text input" );
401
} );
402
 
403
QUnit.test( "#1760 - step modulo/remainder regression tests", function( assert ) {
404
	var v = jQuery( "#form" ).validate(),
405
		method = $.validator.methods.step,
406
		param = 0.00125,
407
		e = $( "#value4" );
408
 
409
	for ( var i = 1; i <= 1000; i++ ) {
410
		e[ 0 ].value = ( param * 100000 * i ) / 100000;
411
		assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Ensure " + e[ 0 ].value + " % " + param + " === 0 is valid" );
412
	}
413
} );
414
 
415
QUnit.test( "lessThan", function( assert ) {
416
	var v = jQuery( "#form" ).validate(),
417
		method = $.validator.methods.lessThan,
418
		e = $( "#value2" );
419
 
420
	assert.ok( method.call( v, "1", e[ 0 ], "#value2" ), "Valid integer" );
421
	assert.ok( !method.call( v, "10", e[ 0 ], "#value2" ), "Invalid integer" );
422
	assert.ok( !method.call( v, "11", e[ 0 ], "#value2" ), "Invalid integer" );
423
} );
424
 
425
QUnit.test( "lessThanEqual", function( assert ) {
426
	var v = jQuery( "#form" ).validate(),
427
		method = $.validator.methods.lessThanEqual,
428
		e = $( "#value2" );
429
 
430
	assert.ok( method.call( v, "1", e[ 0 ], "#value2" ), "Valid integer" );
431
	assert.ok( method.call( v, "10", e[ 0 ], "#value2" ), "Valid integer" );
432
	assert.ok( !method.call( v, "11", e[ 0 ], "#value2" ), "Invalid integer" );
433
} );
434
 
435
QUnit.test( "equalTo", function( assert ) {
436
	var v = jQuery( "#form" ).validate(),
437
		method = $.validator.methods.equalTo,
438
		e = $( "#text1, #text2" );
439
 
440
	assert.ok( method.call( v, "Test", e[ 0 ], "#text1" ), "Text input" );
441
	assert.ok( method.call( v, "T", e[ 1 ], "#text2" ), "Another one" );
442
} );
443
 
444
QUnit.test( "greaterThanEqual", function( assert ) {
445
	var v = jQuery( "#form" ).validate(),
446
		method = $.validator.methods.greaterThanEqual,
447
		e = $( "#value2" );
448
 
449
	assert.ok( !method.call( v, "1", e[ 0 ], "#value2" ), "Invalid integer" );
450
	assert.ok( method.call( v, "10", e[ 0 ], "#value2" ), "Valid integer" );
451
	assert.ok( method.call( v, "11", e[ 0 ], "#value2" ), "Valid integer" );
452
} );
453
 
454
QUnit.test( "greaterThan", function( assert ) {
455
	var v = jQuery( "#form" ).validate(),
456
		method = $.validator.methods.greaterThan,
457
		e = $( "#value2" );
458
 
459
	assert.ok( !method.call( v, "1", e[ 0 ], "#value2" ), "Invalid integer" );
460
	assert.ok( !method.call( v, "10", e[ 0 ], "#value2" ), "Invalid integer" );
461
	assert.ok( method.call( v, "11", e[ 0 ], "#value2" ), "Valid integer" );
462
} );
463
 
464
QUnit.test( "extension", function( assert ) {
465
	var method = methodTest( "extension" ),
466
		v;
467
	assert.ok( method( "picture.gif" ), "Valid default accept type" );
468
	assert.ok( method( "picture.jpg" ), "Valid default accept type" );
469
	assert.ok( method( "picture.jpeg" ), "Valid default accept type" );
470
	assert.ok( method( "picture.png" ), "Valid default accept type" );
471
	assert.ok( !method( "picture.pgn" ), "Invalid default accept type" );
472
 
473
	v = jQuery( "#form" ).validate();
474
	method = function( value, param ) {
475
		return $.validator.methods.extension.call( v, value, $( "#text1" )[ 0 ], param );
476
	};
477
	assert.ok( method( "picture.doc", "doc" ), "Valid custom accept type" );
478
	assert.ok( method( "picture.pdf", "doc|pdf" ), "Valid custom accept type" );
479
	assert.ok( method( "picture.pdf", "pdf|doc" ), "Valid custom accept type" );
480
	assert.ok( !method( "picture.pdf", "doc" ), "Invalid custom accept type" );
481
	assert.ok( !method( "picture.doc", "pdf" ), "Invalid custom accept type" );
482
 
483
	assert.ok( method( "picture.pdf", "doc,pdf" ), "Valid custom accept type, comma separated" );
484
	assert.ok( method( "picture.pdf", "pdf,doc" ), "Valid custom accept type, comma separated" );
485
	assert.ok( !method( "picture.pdf", "gop,top" ), "Invalid custom accept type, comma separated" );
486
} );
487
 
488
QUnit.test( "remote", function( assert ) {
489
	assert.expect( 7 );
490
	var e = $( "#username" ),
491
		v = $( "#userForm" ).validate( {
492
			rules: {
493
				username: {
494
					required: true,
495
					remote: "users.php"
496
				}
497
			},
498
			messages: {
499
				username: {
500
					required: "Please",
501
					remote: jQuery.validator.format( "{0} in use" )
502
				}
503
			}
504
		} ),
505
		done = assert.async();
506
 
507
	$( document ).ajaxStop( function() {
508
		$( document ).unbind( "ajaxStop" );
509
		assert.equal( v.size(), 1, "There must be one error" );
510
		assert.equal( v.errorList[ 0 ].message, "Peter in use" );
511
 
512
		$( document ).ajaxStop( function() {
513
			$( document ).unbind( "ajaxStop" );
514
			assert.equal( v.size(), 1, "There must be one error" );
515
			assert.equal( v.errorList[ 0 ].message, "Peter2 in use" );
516
			done();
517
		} );
518
		e.val( "Peter2" );
519
		assert.strictEqual( v.element( e ), true, "new value, new request; dependency-mismatch considered as valid though" );
520
	} );
521
	assert.strictEqual( v.element( e ), false, "invalid element, nothing entered yet" );
522
	e.val( "Peter" );
523
	assert.strictEqual( v.element( e ), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" );
524
} );
525
 
526
QUnit.test( "remote, pending class added to element while call outstanding", function( assert ) {
527
	assert.expect( 3 );
528
	var e = $( "#username" ),
529
		done = assert.async(),
530
		v = $( "#userForm" ).validate( {
531
			rules: {
532
				username: {
533
					remote: {
534
						url: "users.php",
535
						complete: function() {
536
							assert.strictEqual( e.hasClass( "pending" ), false, "not pending since ajax call complete" );
537
							done();
538
						}
539
					}
540
				}
541
			}
542
		} );
543
	assert.strictEqual( e.hasClass( "pending" ), false, "not pending since no data entered" );
544
	e.val( "Peter" );
545
 
546
	// This fires off the validation:
547
	v.element( e );
548
	assert.strictEqual( e.hasClass( "pending" ), true, "pending while validation outstanding" );
549
} );
550
 
551
QUnit.test( "remote, customized ajax options", function( assert ) {
552
	assert.expect( 2 );
553
	var done = assert.async();
554
	$( "#userForm" ).validate( {
555
		rules: {
556
			username: {
557
				required: true,
558
				remote: {
559
					url: "users.php",
560
					type: "POST",
561
					beforeSend: function( request, settings ) {
562
						assert.deepEqual( settings.type, "POST" );
563
						assert.deepEqual( settings.data, "username=asdf&email=email.com" );
564
					},
565
					data: {
566
						email: function() {
567
							return "email.com";
568
						}
569
					},
570
					complete: function() {
571
						done();
572
					}
573
				}
574
			}
575
		}
576
	} );
577
	$( "#username" ).val( "asdf" );
578
	$( "#userForm" ).valid();
579
} );
580
 
581
QUnit.test( "remote extensions", function( assert ) {
582
	assert.expect( 5 );
583
	var e = $( "#username" ),
584
		v = $( "#userForm" ).validate( {
585
			rules: {
586
				username: {
587
					required: true,
588
					remote: "users2.php"
589
				}
590
			},
591
			messages: {
592
				username: {
593
					required: "Please"
594
				}
595
			}
596
		} ),
597
		done = assert.async();
598
 
599
	$( document ).ajaxStop( function() {
600
		$( document ).unbind( "ajaxStop" );
601
		if ( v.size() !== 0 ) {
602
			assert.ok( "There must be one error" );
603
			assert.equal( v.errorList[ 0 ].message, "asdf is already taken, please try something else" );
604
			v.element( e );
605
			assert.equal( v.errorList[ 0 ].message, "asdf is already taken, please try something else", "message doesn't change on revalidation" );
606
		}
607
		done();
608
	} );
609
	assert.strictEqual( v.element( e ), false, "invalid element, nothing entered yet" );
610
	e.val( "asdf" );
611
	assert.strictEqual( v.element( e ), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" );
612
} );
613
 
614
QUnit.test( "remote, data previous querystring", function( assert ) {
615
	assert.expect( 4 );
616
	var succeeded = 0,
617
		$f = $( "#firstnamec" ),
618
		$l = $( "#lastnamec" ),
619
		done1 = assert.async(),
620
		done2 = assert.async(),
621
		done3 = assert.async(),
622
		v = $( "#testForm1clean" ).validate( {
623
			rules: {
624
				lastname: {
625
					remote: {
626
						url: "users.php",
627
						type: "POST",
628
						data: {
629
							firstname: function() {
630
								return $f.val();
631
							}
632
						},
633
						complete: function() {
634
							succeeded++;
635
						}
636
					}
637
				}
638
			}
639
		} );
640
	$f.val( "first-name" );
641
	$l.val( "last-name" );
642
	assert.strictEqual( succeeded, 0, "no valid call means no successful validation" );
643
	v.element( $l );
644
	setTimeout( function() {
645
		assert.strictEqual( succeeded, 1, "first valid check should submit given first name" );
646
		done1();
647
		v.element( $l );
648
		setTimeout( function() {
649
			assert.strictEqual( succeeded, 1, "second valid check should not resubmit given same first name" );
650
			done2();
651
			$f.val( "different-first-name" );
652
			v.element( $l );
653
			setTimeout( function() {
654
				assert.strictEqual( succeeded, 2, "third valid check should resubmit given different first name" );
655
				done3();
656
			} );
657
		} );
658
	} );
659
} );
660
 
661
QUnit.test( "remote, highlight all invalid fields", function( assert ) {
662
	assert.expect( 3 );
663
 
664
	var done = assert.async(),
665
		$form = $( "#testForm1" ),
666
		$firstnameField = $form.find( "input[name='firstname']" ),
667
		$lastnameField = $form.find( "input[name='lastname']" ),
668
		$somethingField = $form.find( "input[name='something']" ),
669
		validateOptions = {
670
	        rules: {
671
				firstname: {
672
	                required: true
673
	            },
674
	            lastname: {
675
	                required: true
676
	            },
677
				something: {
678
	                required: true,
679
	                remote: {
680
	                    url: "response.php",
681
	                    type: "post",
682
						data: {
683
							responseText: "false"
684
						}
685
					}
686
				}
687
			}
688
		};
689
 
690
	$firstnameField.val( "" );
691
	$lastnameField.val( "" );
692
	$somethingField.val( "something value" );
693
 
694
	$form.validate( validateOptions );
695
	$form.valid();
696
 
697
	setTimeout( function() {
698
		assert.equal( $firstnameField.hasClass( "error" ), true, "Field 'firstname' should have a '.error' class" );
699
		assert.equal( $lastnameField.hasClass( "error" ), true, "Field 'lastname' should have a '.error' class" );
700
		assert.equal( $somethingField.hasClass( "error" ), true, "Field 'something' should have a '.error' class" );
701
		done();
702
	}, 500 );
703
} );
704
QUnit.test( "remote, unhighlighted should be invoked after being highlighted/invalid", function( assert ) {
705
	assert.expect( 6 );
706
 
707
	var done1 = assert.async(),
708
		done2 = assert.async(),
709
		$form = $( "#testForm25" ),
710
		$somethingField = $form.find( "input[name='something25']" ),
711
		responseText = "false",
712
		response = function() { return responseText; },
713
		validateOptions = {
714
			highlight: function( e ) {
715
				$( e ).addClass( "error" );
716
				assert.ok( true, "highlight should be called" );
717
			},
718
			unhighlight: function( e ) {
719
				$( e ).removeClass( "error" );
720
				assert.ok( true, "unhighlight should be called" );
721
			},
722
	        rules: {
723
				something25: {
724
	                required: true,
725
	                remote: {
726
	                    url: "response.php",
727
	                    type: "post",
728
						data: {
729
							responseText: response
730
						},
731
						async: false
732
					}
733
				}
734
			}
735
		};
736
 
737
	$somethingField.val( "something value" );
738
	var v = $form.validate( validateOptions );
739
	v.element( $somethingField );
740
 
741
	setTimeout( function() {
742
		assert.equal( $somethingField.hasClass( "error" ), true, "Field 'something' should have the error class" );
743
		done1();
744
		$somethingField.val( "something value 2" );
745
		responseText = "true";
746
 
747
		v.element( $somethingField );
748
 
749
		setTimeout( function() {
750
			assert.equal( $somethingField.hasClass( "error" ), false, "Field 'something' should not have the error class" );
751
			done2();
752
		}, 500 );
753
	}, 500 );
754
} );
755
 
756
QUnit.test( "Fix #697: remote validation uses wrong error messages", function( assert ) {
757
	var e = $( "#username" ),
758
		done1 = assert.async(),
759
		done2 = assert.async(),
760
		done3 = assert.async(),
761
		v = $( "#userForm" ).validate( {
762
			rules: {
763
				username: {
764
					required: true,
765
					remote: {
766
						url: "users.php"
767
					}
768
				}
769
			},
770
			messages: {
771
				username: {
772
					remote: $.validator.format( "{0} in use" )
773
				}
774
			}
775
		} );
776
 
777
	$( "#userForm" ).valid();
778
 
779
	e.val( "Peter" );
780
	v.element( e );
781
	setTimeout( function() {
782
		assert.equal( v.errorList[ 0 ].message, "Peter in use" );
783
		done1();
784
 
785
		e.val( "something" );
786
		v.element( e );
787
 
788
		e.val( "Peter" );
789
		v.element( e );
790
		setTimeout( function() {
791
			assert.equal( v.errorList[ 0 ].message, "Peter in use" );
792
			done2();
793
 
794
			e.val( "asdf" );
795
			v.element( e );
796
			setTimeout( function() {
797
				assert.equal( v.errorList[ 0 ].message, "asdf in use", "error message should be updated" );
798
				done3();
799
			} );
800
		} );
801
	} );
802
} );
803
 
804
QUnit.module( "additional methods" );
805
 
806
QUnit.test( "phone (us)", function( assert ) {
807
	var method = methodTest( "phoneUS" );
808
	assert.ok( method( "1(212)-999-2345" ), "Valid US phone number" );
809
	assert.ok( method( "212 999 2344" ), "Valid US phone number" );
810
	assert.ok( method( "212-999-0983" ), "Valid US phone number" );
811
	assert.ok( method( "234-911-5678" ), "Valid US phone number" );
812
	assert.ok( !method( "111-123-5434" ), "Invalid US phone number. Area Code cannot start with 1" );
813
	assert.ok( !method( "212 123 4567" ), "Invalid US phone number. NXX cannot start with 1" );
814
	assert.ok( !method( "911-333-5678" ), "Invalid US phone number, because the area code cannot be in the form N11" );
815
	assert.ok( method( "234-912-5678" ), "Valid US phone number" );
816
} );
817
 
818
QUnit.test( "phoneUK", function( assert ) {
819
	var method = methodTest( "phoneUK" );
820
	assert.ok( method( "0117 333 5555" ), "Valid UK Phone Number" );
821
	assert.ok( method( "0121 555 5555" ), "Valid UK Phone Number" );
822
	assert.ok( method( "01633 555555" ), "Valid UK Phone Number" );
823
	assert.ok( method( "01298 28555" ), "Valid UK Phone Number" );
824
	assert.ok( method( "015395 55555" ), "Valid UK Phone Number" );
825
	assert.ok( method( "016977 3999" ), "Valid UK Phone Number" );
826
	assert.ok( method( "020 3000 5555" ), "Valid UK Phone Number" );
827
	assert.ok( method( "024 7500 5555" ), "Valid UK Phone Number" );
828
	assert.ok( method( "0333 555 5555" ), "Valid UK Phone Number" );
829
	assert.ok( method( "0500 555555" ), "Valid UK Phone Number" );
830
	assert.ok( method( "055 3555 5555" ), "Valid UK Phone Number" );
831
	assert.ok( method( "07122 555555" ), "Valid UK Phone Number" );
832
	assert.ok( method( "07222 555555" ), "Valid UK Phone Number" );
833
	assert.ok( method( "07322 555555" ), "Valid UK Phone Number" );
834
	assert.ok( method( "0800 555 5555" ), "Valid UK Phone Number" );
835
	assert.ok( method( "0800 355555" ), "Valid UK Phone Number" );
836
	assert.ok( method( "0843 555 5555" ), "Valid UK Phone Number" );
837
	assert.ok( method( "0872 555 5555" ), "Valid UK Phone Number" );
838
	assert.ok( method( "0903 555 5555" ), "Valid UK Phone Number" );
839
	assert.ok( method( "0983 555 5555" ), "Valid UK Phone Number" );
840
	assert.ok( method( "(07122) 555555" ), "Valid UK Phone Number" );
841
	assert.ok( method( "(07222) 555555" ), "Valid UK Phone Number" );
842
	assert.ok( method( "(07322) 555555" ), "Valid UK Phone Number" );
843
	assert.ok( method( "+44 7122 555 555" ), "Valid UK Phone Number" );
844
	assert.ok( method( "+44 7222 555 555" ), "Valid UK Phone Number" );
845
	assert.ok( method( "+44 7322 555 555" ), "Valid UK Phone Number" );
846
	assert.ok( !method( "7222 555555" ), "Invalid UK Phone Number" );
847
	assert.ok( !method( "+44 07222 555555" ), "Invalid UK Phone Number" );
848
} );
849
 
850
QUnit.test( "mobileUK", function( assert ) {
851
	var method = methodTest( "mobileUK" );
852
	assert.ok( method( "07134234323" ), "Valid UK Mobile Number" );
853
	assert.ok( method( "07334234323" ), "Valid UK Mobile Number" );
854
	assert.ok( method( "07624234323" ), "Valid UK Mobile Number" );
855
	assert.ok( method( "07734234323" ), "Valid UK Mobile Number" );
856
	assert.ok( method( "+447134234323" ), "Valid UK Mobile Number" );
857
	assert.ok( method( "+447334234323" ), "Valid UK Mobile Number" );
858
	assert.ok( method( "+447624234323" ), "Valid UK Mobile Number" );
859
	assert.ok( method( "+447734234323" ), "Valid UK Mobile Number" );
860
	assert.ok( !method( "07034234323" ), "Invalid UK Mobile Number" );
861
	assert.ok( !method( "0753423432" ), "Invalid UK Mobile Number" );
862
	assert.ok( !method( "07604234323" ), "Invalid UK Mobile Number" );
863
	assert.ok( !method( "077342343234" ), "Invalid UK Mobile Number" );
864
	assert.ok( !method( "044342343234" ), "Invalid UK Mobile Number" );
865
	assert.ok( !method( "+44753423432" ), "Invalid UK Mobile Number" );
866
	assert.ok( !method( "+447604234323" ), "Invalid UK Mobile Number" );
867
	assert.ok( !method( "+4477342343234" ), "Invalid UK Mobile Number" );
868
	assert.ok( !method( "+4444342343234" ), "Invalid UK Mobile Number" );
869
} );
870
 
871
QUnit.test( "mobileRU", function( assert ) {
872
	var method = methodTest( "mobileRU" );
873
	assert.ok( method( "+74957207089" ), "Valid RU Mobile Number" );
874
	assert.ok( method( "84957207089" ), "Valid RU Mobile Number" );
875
	assert.ok( !method( "+447604234323" ), "Invalid RU Mobile Number" );
876
	assert.ok( !method( "9477342343234" ), "Invalid RU Mobile Number" );
877
	assert.ok( !method( "344342343234" ), "Invalid RU Mobile Number" );
878
} );
879
 
880
QUnit.test( "dateITA", function( assert ) {
881
	var method = methodTest( "dateITA" );
882
	assert.ok( method( "01/01/1900" ), "Valid date ITA" );
883
	assert.ok( method( "17/10/2010" ), "Valid date ITA" );
884
	assert.ok( !method( "01/13/1990" ), "Invalid date ITA" );
885
	assert.ok( !method( "01.01.1900" ), "Invalid date ITA" );
886
	assert.ok( !method( "01/01/199" ), "Invalid date ITA" );
887
} );
888
 
889
QUnit.test( "dateFA", function( assert ) {
890
	var method = methodTest( "dateFA" );
891
 
892
	assert.ok( method( "1342/12/29" ), "Valid date FA" );
893
	assert.ok( method( "1342/12/30" ), "Valid date FA" );
894
	assert.ok( method( "1361/6/31" ), "Valid date FA" );
895
	assert.ok( method( "1321/11/30" ), "Valid date FA" );
896
	assert.ok( method( "1361/1/1" ), "Valid date FA" );
897
	assert.ok( method( "1020/3/3" ), "Valid date FA" );
898
	assert.ok( method( "1020/03/3" ), "Valid date FA" );
899
	assert.ok( method( "1020/3/03" ), "Valid date FA" );
900
	assert.ok( method( "1020/03/03" ), "Valid date FA" );
901
	assert.ok( method( "1001/7/30" ), "Valid date FA" );
902
 
903
	assert.ok( !method( "1000/1/32" ), "Invalid date FA" );
904
	assert.ok( !method( "1323/12/31" ), "Invalid date FA" );
905
	assert.ok( !method( "1361/0/11" ), "Invalid date FA" );
906
	assert.ok( !method( "63/4/4" ), "Invalid date FA" );
907
	assert.ok( !method( "15/6/1361" ), "Invalid date FA" );
908
} );
909
 
910
QUnit.test( "iban", function( assert ) {
911
	var method = methodTest( "iban" );
912
	assert.ok( method( "NL20INGB0001234567" ), "Valid IBAN" );
913
	assert.ok( method( "DE68 2105 0170 0012 3456 78" ), "Valid IBAN" );
914
	assert.ok( method( "NL20 INGB0001234567" ), "Valid IBAN: invalid spacing" );
915
	assert.ok( method( "NL20 INGB 00 0123 4567" ), "Valid IBAN: invalid spacing" );
916
	assert.ok( method( "XX40INGB000123456712341234" ), "Valid (more or less) IBAN: unknown country, but checksum OK" );
917
 
918
	assert.ok( !method( "1" ), "Invalid IBAN: too short" );
919
	assert.ok( !method( "NL20INGB000123456" ), "Invalid IBAN: too short" );
920
	assert.ok( !method( "NL20INGB00012345678" ), "Invalid IBAN: too long" );
921
	assert.ok( !method( "NL20INGB0001234566" ), "Invalid IBAN: checksum incorrect" );
922
	assert.ok( !method( "DE68 2105 0170 0012 3456 7" ), "Invalid IBAN: too short" );
923
	assert.ok( !method( "DE68 2105 0170 0012 3456 789" ), "Invalid IBAN: too long" );
924
	assert.ok( !method( "DE68 2105 0170 0012 3456 79" ), "Invalid IBAN: checksum incorrect" );
925
 
926
	assert.ok( !method( "NL54INGB00012345671234" ), "Invalid IBAN too long, BUT CORRECT CHECKSUM" );
927
	assert.ok( !method( "XX00INGB000123456712341234" ), "Invalid IBAN: unknown country and checksum incorrect" );
928
 
929
	// Sample IBANs for different countries
930
	assert.ok( method( "AL47 2121 1009 0000 0002 3569 8741" ), "Valid IBAN - AL" );
931
	assert.ok( method( "AD12 0001 2030 2003 5910 0100" ), "Valid IBAN - AD" );
932
	assert.ok( method( "AT61 1904 3002 3457 3201" ), "Valid IBAN - AT" );
933
	assert.ok( method( "AZ21 NABZ 0000 0000 1370 1000 1944" ), "Valid IBAN - AZ" );
934
	assert.ok( method( "BH67 BMAG 0000 1299 1234 56" ), "Valid IBAN - BH" );
935
	assert.ok( method( "BE62 5100 0754 7061" ), "Valid IBAN - BE" );
936
	assert.ok( method( "BA39 1290 0794 0102 8494" ), "Valid IBAN - BA" );
937
	assert.ok( method( "BG80 BNBG 9661 1020 3456 78" ), "Valid IBAN - BG" );
938
	assert.ok( method( "HR12 1001 0051 8630 0016 0" ), "Valid IBAN - HR" );
939
	assert.ok( method( "CH93 0076 2011 6238 5295 7" ), "Valid IBAN - CH" );
940
	assert.ok( method( "CY17 0020 0128 0000 0012 0052 7600" ), "Valid IBAN - CY" );
941
	assert.ok( method( "CZ65 0800 0000 1920 0014 5399" ), "Valid IBAN - CZ" );
942
	assert.ok( method( "DK50 0040 0440 1162 43" ), "Valid IBAN - DK" );
943
	assert.ok( method( "EE38 2200 2210 2014 5685" ), "Valid IBAN - EE" );
944
	assert.ok( method( "FO97 5432 0388 8999 44" ), "Valid IBAN - FO" );
945
	assert.ok( method( "FI21 1234 5600 0007 85" ), "Valid IBAN - FI" );
946
	assert.ok( method( "FR14 2004 1010 0505 0001 3M02 606" ), "Valid IBAN - FR" );
947
	assert.ok( method( "GE29 NB00 0000 0101 9049 17" ), "Valid IBAN - GE" );
948
	assert.ok( method( "DE89 3704 0044 0532 0130 00" ), "Valid IBAN - DE" );
949
	assert.ok( method( "GI75 NWBK 0000 0000 7099 453" ), "Valid IBAN - GI" );
950
	assert.ok( method( "GR16 0110 1250 0000 0001 2300 695" ), "Valid IBAN - GR" );
951
	assert.ok( method( "GL56 0444 9876 5432 10" ), "Valid IBAN - GL" );
952
	assert.ok( method( "HU42 1177 3016 1111 1018 0000 0000" ), "Valid IBAN - HU" );
953
	assert.ok( method( "IS14 0159 2600 7654 5510 7303 39" ), "Valid IBAN - IS" );
954
	assert.ok( method( "IE29 AIBK 9311 5212 3456 78" ), "Valid IBAN - IE" );
955
	assert.ok( method( "IL62 0108 0000 0009 9999 999" ), "Valid IBAN - IL" );
956
	assert.ok( method( "IT40 S054 2811 1010 0000 0123 456" ), "Valid IBAN - IT" );
957
	assert.ok( method( "LV80 BANK 0000 4351 9500 1" ), "Valid IBAN - LV" );
958
	assert.ok( method( "LB62 0999 0000 0001 0019 0122 9114" ), "Valid IBAN - LB" );
959
	assert.ok( method( "LI21 0881 0000 2324 013A A" ), "Valid IBAN - LI" );
960
	assert.ok( method( "LT12 1000 0111 0100 1000" ), "Valid IBAN - LT" );
961
	assert.ok( method( "LU28 0019 4006 4475 0000" ), "Valid IBAN - LU" );
962
	assert.ok( method( "MK07 2501 2000 0058 984" ), "Valid IBAN - MK" );
963
	assert.ok( method( "MT84 MALT 0110 0001 2345 MTLC AST0 01S" ), "Valid IBAN - MT" );
964
	assert.ok( method( "MU17 BOMM 0101 1010 3030 0200 000M UR" ), "Valid IBAN - MU" );
965
	assert.ok( method( "MD24 AG00 0225 1000 1310 4168" ), "Valid IBAN - MD" );
966
	assert.ok( method( "MC93 2005 2222 1001 1223 3M44 555" ), "Valid IBAN - MC" );
967
	assert.ok( method( "ME25 5050 0001 2345 6789 51" ), "Valid IBAN - ME" );
968
	assert.ok( method( "NL39 RABO 0300 0652 64" ), "Valid IBAN - NL" );
969
	assert.ok( method( "NO93 8601 1117 947" ), "Valid IBAN - NO" );
970
	assert.ok( method( "PK36 SCBL 0000 0011 2345 6702" ), "Valid IBAN - PK" );
971
	assert.ok( method( "PL60 1020 1026 0000 0422 7020 1111" ), "Valid IBAN - PL" );
972
	assert.ok( method( "PT50 0002 0123 1234 5678 9015 4" ), "Valid IBAN - PT" );
973
	assert.ok( method( "RO49 AAAA 1B31 0075 9384 0000" ), "Valid IBAN - RO" );
974
	assert.ok( method( "SM86 U032 2509 8000 0000 0270 100" ), "Valid IBAN - SM" );
975
	assert.ok( method( "SA03 8000 0000 6080 1016 7519" ), "Valid IBAN - SA" );
976
	assert.ok( method( "RS35 2600 0560 1001 6113 79" ), "Valid IBAN - RS" );
977
	assert.ok( method( "SK31 1200 0000 1987 4263 7541" ), "Valid IBAN - SK" );
978
	assert.ok( method( "SI56 1910 0000 0123 438" ), "Valid IBAN - SI" );
979
	assert.ok( method( "ES80 2310 0001 1800 0001 2345" ), "Valid IBAN - ES" );
980
	assert.ok( method( "SE35 5000 0000 0549 1000 0003" ), "Valid IBAN - SE" );
981
	assert.ok( method( "CH93 0076 2011 6238 5295 7" ), "Valid IBAN - CH" );
982
	assert.ok( method( "TN59 1000 6035 1835 9847 8831" ), "Valid IBAN - TN" );
983
	assert.ok( method( "TR33 0006 1005 1978 6457 8413 26" ), "Valid IBAN - TR" );
984
	assert.ok( method( "AE07 0331 2345 6789 0123 456" ), "Valid IBAN - AE" );
985
	assert.ok( method( "GB29 NWBK 6016 1331 9268 19" ), "Valid IBAN - GB" );
986
} );
987
 
988
/**
989
 * BIC tests (For BIC definition take a look on the implementation itself)
990
 */
991
QUnit.test( "bic", function( assert ) {
992
	var method = methodTest( "bic" );
993
 
994
	assert.ok( !method( "PBNKDEF" ), "Invalid BIC: too short" );
995
	assert.ok( !method( "DEUTDEFFA1" ), "Invalid BIC: disallowed length" );
996
	assert.ok( !method( "PBNKDEFFXXX1" ), "Invalid BIC: too long" );
997
	assert.ok( !method( "1BNKDEFF" ), "Invalid BIC: invalid digit" );
998
	assert.ok( !method( "PBNKDE1F" ), "Invalid BIC: invalid digit" );
999
	assert.ok( !method( "PBNKDEFO" ), "Invalid BIC: invalid char" );
1000
	assert.ok( !method( "INGDDEFFXAA" ), "Invalid BIC: invalid char" );
1001
	assert.ok( !method( "DEUTDEF0" ), "Invalid BIC: invalid digit" );
1002
 
1003
	assert.ok( method( "DEUTDEFF" ), "Valid BIC" );
1004
	assert.ok( method( "DEUTDEFFXXX" ), "Valid BIC" );
1005
	assert.ok( method( "PBNKDE2F" ), "Valid BIC" );
1006
	assert.ok( method( "INGDDEFF101" ), "Valid BIC" );
1007
	assert.ok( method( "INGDDEF2134" ), "Valid BIC" );
1008
	assert.ok( method( "INGDDE91XXX" ), "Valid BIC" );
1009
	assert.ok( method( "INGDDEF2" ), "Valid BIC" );
1010
	assert.ok( method( "AAFFFRP1" ), "Valid BIC" );
1011
	assert.ok( method( "DEUTDEFFAB1" ), "Valid BIC" );
1012
	assert.ok( method( "DEUTDEFFAXX" ), "Valid BIC" );
1013
	assert.ok( method( "SSKNDE77XXX" ), "Valid BIC" );
1014
 
1015
	// BIC accept also lowercased values
1016
	assert.ok( !method( "pbnkdef" ), "Invalid BIC: too short" );
1017
	assert.ok( !method( "deutdeffa1" ), "Invalid BIC: disallowed length" );
1018
	assert.ok( !method( "pbnkdeffxxx1" ), "Invalid BIC: too long" );
1019
	assert.ok( !method( "1bnkdeff" ), "Invalid BIC: invalid digit" );
1020
	assert.ok( !method( "ingddeffxaa" ), "Invalid BIC: invalid char" );
1021
 
1022
	assert.ok( method( "deutdeff" ), "Valid BIC (lowercase value)" );
1023
	assert.ok( method( "deutdeffxxx" ), "Valid BIC (lowercase value)" );
1024
	assert.ok( method( "pbnkde2f" ), "Valid BIC (lowercase value)" );
1025
	assert.ok( method( "ingdde91xxx" ), "Valid BIC (lowercase value)" );
1026
	assert.ok( method( "ingddef2" ), "Valid BIC (lowercase value)" );
1027
	assert.ok( method( "deutdeffab1" ), "Valid BIC (lowercase value)" );
1028
} );
1029
 
1030
QUnit.test( "postcodeUK", function( assert ) {
1031
	var method = methodTest( "postcodeUK" );
1032
	assert.ok( method( "AA9A 9AA" ), "Valid postcode" );
1033
	assert.ok( method( "A9A 9AA" ), "Valid postcode" );
1034
	assert.ok( method( "A9 9AA" ), "Valid postcode" );
1035
	assert.ok( method( "A99 9AA" ), "Valid postcode" );
1036
	assert.ok( method( "AA9 9AA" ), "Valid postcode" );
1037
	assert.ok( method( "AA99 9AA" ), "Valid postcode" );
1038
 
1039
	// Channel Island
1040
	assert.ok( !method( "AAAA 9AA" ), "Invalid postcode" );
1041
	assert.ok( !method( "AA-2640" ), "Invalid postcode" );
1042
 
1043
	assert.ok( !method( "AAA AAA" ), "Invalid postcode" );
1044
	assert.ok( !method( "AA AAAA" ), "Invalid postcode" );
1045
	assert.ok( !method( "A AAAA" ), "Invalid postcode" );
1046
	assert.ok( !method( "AAAAA" ), "Invalid postcode" );
1047
	assert.ok( !method( "999 999" ), "Invalid postcode" );
1048
	assert.ok( !method( "99 9999" ), "Invalid postcode" );
1049
	assert.ok( !method( "9 9999" ), "Invalid postcode" );
1050
	assert.ok( !method( "99999" ), "Invalid postcode" );
1051
} );
1052
 
1053
QUnit.test( "dateNL", function( assert ) {
1054
	var method = methodTest( "dateNL" );
1055
	assert.ok( method( "01-01-1900" ), "Valid date NL" );
1056
	assert.ok( method( "01.01.1900" ), "Valid date NL" );
1057
	assert.ok( method( "01/01/1900" ), "Valid date NL" );
1058
	assert.ok( method( "01-01-00" ), "Valid date NL" );
1059
	assert.ok( method( "1-01-1900" ), "Valid date NL" );
1060
	assert.ok( method( "10-10-1900" ), "Valid date NL" );
1061
	assert.ok( !method( "0-01-1900" ), "Invalid date NL" );
1062
	assert.ok( !method( "00-01-1900" ), "Invalid date NL" );
1063
	assert.ok( !method( "35-01-1990" ), "Invalid date NL" );
1064
	assert.ok( !method( "01.01.190" ), "Invalid date NL" );
1065
} );
1066
 
1067
QUnit.test( "phoneNL", function( assert ) {
1068
	var method = methodTest( "phoneNL" );
1069
	assert.ok( method( "0701234567" ), "Valid phone NL" );
1070
	assert.ok( method( "0687654321" ), "Valid phone NL" );
1071
	assert.ok( method( "020-1234567" ), "Valid phone NL" );
1072
	assert.ok( method( "020 - 12 34 567" ), "Valid phone NL" );
1073
	assert.ok( method( "010-2345678" ), "Valid phone NL" );
1074
	assert.ok( method( "+3120-1234567" ), "Valid phone NL" );
1075
	assert.ok( method( "+31(0)10-2345678" ), "Valid phone NL" );
1076
	assert.ok( !method( "020-123456" ), "Invalid phone NL: too short" );
1077
	assert.ok( !method( "020-12345678" ), "Invalid phone NL: too long" );
1078
	assert.ok( !method( "-0201234567" ), "Invalid phone NL" );
1079
	assert.ok( !method( "+310201234567" ), "Invalid phone NL: no 0 after +31 allowed" );
1080
} );
1081
 
1082
QUnit.test( "mobileNL", function( assert ) {
1083
	var method = methodTest( "mobileNL" );
1084
	assert.ok( method( "0612345678" ), "Valid NL Mobile Number" );
1085
	assert.ok( method( "06-12345678" ), "Valid NL Mobile Number" );
1086
	assert.ok( method( "06-12 345 678" ), "Valid NL Mobile Number" );
1087
	assert.ok( method( "+316-12345678" ), "Valid NL Mobile Number" );
1088
	assert.ok( method( "+31(0)6-12345678" ), "Valid NL Mobile Number" );
1089
	assert.ok( !method( "abcdefghij" ), "Invalid NL Mobile Number: text" );
1090
	assert.ok( !method( "0123456789" ), "Invalid NL Mobile Number: should start with 06" );
1091
	assert.ok( !method( "0823456789" ), "Invalid NL Mobile Number: should start with 06" );
1092
	assert.ok( !method( "06-1234567" ), "Invalid NL Mobile Number: too short" );
1093
	assert.ok( !method( "06-123456789" ), "Invalid NL Mobile Number: too long" );
1094
	assert.ok( !method( "-0612345678" ), "Invalid NL Mobile Number" );
1095
	assert.ok( !method( "+310612345678" ), "Invalid NL Mobile Number: no 0 after +31 allowed" );
1096
} );
1097
 
1098
QUnit.test( "postalcodeNL", function( assert ) {
1099
	var method = methodTest( "postalcodeNL" );
1100
	assert.ok( method( "1234AB" ), "Valid NL Postal Code" );
1101
	assert.ok( method( "1234ab" ), "Valid NL Postal Code" );
1102
	assert.ok( method( "1234 AB" ), "Valid NL Postal Code" );
1103
	assert.ok( method( "6789YZ" ), "Valid NL Postal Code" );
1104
	assert.ok( !method( "123AA" ), "Invalid NL Postal Code: not enough digits" );
1105
	assert.ok( !method( "12345ZZ" ), "Invalid NL Postal Code: too many digits" );
1106
	assert.ok( !method( "1234  AA" ), "Invalid NL Postal Code: too many spaces" );
1107
	assert.ok( !method( "AA1234" ), "Invalid NL Postal Code" );
1108
	assert.ok( !method( "1234-AA" ), "Invalid NL Postal Code" );
1109
} );
1110
 
1111
QUnit.test( "bankaccountNL", function( assert ) {
1112
	var method = methodTest( "bankaccountNL" );
1113
	assert.ok( method( "755490975" ), "Valid NL bank account" );
1114
	assert.ok( method( "75 54 90 975" ), "Valid NL bank account" );
1115
	assert.ok( method( "123456789" ), "Valid NL bank account" );
1116
	assert.ok( method( "12 34 56 789" ), "Valid NL bank account" );
1117
	assert.ok( !method( "12 3456789" ), "Valid NL bank account: inconsistent spaces" );
1118
	assert.ok( !method( "123 45 67 89" ), "Valid NL bank account: incorrect spaces" );
1119
	assert.ok( !method( "755490971" ), "Invalid NL bank account" );
1120
	assert.ok( !method( "755490973" ), "Invalid NL bank account" );
1121
	assert.ok( !method( "755490979" ), "Invalid NL bank account" );
1122
	assert.ok( !method( "123456781" ), "Invalid NL bank account" );
1123
	assert.ok( !method( "123456784" ), "Invalid NL bank account" );
1124
	assert.ok( !method( "123456788" ), "Invalid NL bank account" );
1125
} );
1126
 
1127
QUnit.test( "giroaccountNL", function( assert ) {
1128
	var method = methodTest( "giroaccountNL" );
1129
	assert.ok( method( "123" ), "Valid NL giro  account" );
1130
	assert.ok( method( "1234567" ), "Valid NL giro account" );
1131
	assert.ok( !method( "123456788" ), "Invalid NL giro account" );
1132
} );
1133
 
1134
QUnit.test( "bankorgiroaccountNL", function( assert ) {
1135
	var method = methodTest( "bankorgiroaccountNL" );
1136
	assert.ok( method( "123" ), "Valid NL giro account" );
1137
	assert.ok( method( "1234567" ), "Valid NL giro account" );
1138
	assert.ok( method( "123456789" ), "Valid NL bank account" );
1139
	assert.ok( !method( "12345678" ), "Invalid NL bank or giro account" );
1140
	assert.ok( !method( "123456788" ), "Invalid NL bank or giro account" );
1141
} );
1142
 
1143
QUnit.test( "time", function( assert ) {
1144
	var method = methodTest( "time" );
1145
	assert.ok( method( "00:00" ), "Valid time, lower bound" );
1146
	assert.ok( method( "23:59" ), "Valid time, upper bound" );
1147
	assert.ok( method( "3:59" ), "Valid time, single digit hour" );
1148
	assert.ok( !method( "12" ), "Invalid time" );
1149
	assert.ok( !method( "29:59" ), "Invalid time" );
1150
	assert.ok( !method( "00:60" ), "Invalid time" );
1151
	assert.ok( !method( "24:60" ), "Invalid time" );
1152
	assert.ok( !method( "24:00" ), "Invalid time" );
1153
	assert.ok( !method( "30:00" ), "Invalid time" );
1154
	assert.ok( !method( "29:59" ), "Invalid time" );
1155
	assert.ok( !method( "120:00" ), "Invalid time" );
1156
	assert.ok( !method( "12:001" ), "Invalid time" );
1157
	assert.ok( !method( "12:00a" ), "Invalid time" );
1158
} );
1159
 
1160
QUnit.test( "time12h", function( assert ) {
1161
	var method = methodTest( "time12h" );
1162
	assert.ok( method( "12:00 AM" ), "Valid time, lower bound, am" );
1163
	assert.ok( method( "11:59 AM" ), "Valid time, upper bound, am" );
1164
	assert.ok( method( "12:00AM" ), "Valid time, no space, am" );
1165
	assert.ok( method( "12:00PM" ), "Valid time, no space, pm" );
1166
	assert.ok( method( "12:00 PM" ), "Valid time, lower bound, pm" );
1167
	assert.ok( method( "11:59 PM" ), "Valid time, upper bound, pm" );
1168
	assert.ok( method( "11:59 am" ), "Valid time, also accept lowercase" );
1169
	assert.ok( method( "11:59 pm" ), "Valid time, also accept lowercase" );
1170
	assert.ok( method( "1:59 pm" ), "Valid time, single hour, no leading 0" );
1171
	assert.ok( method( "01:59 pm" ), "Valid time, single hour, leading 0" );
1172
	assert.ok( !method( "12:00" ), "Invalid time" );
1173
	assert.ok( !method( "9" ), "Invalid time" );
1174
	assert.ok( !method( "9 am" ), "Invalid time" );
1175
	assert.ok( !method( "12:61 am" ), "Invalid time" );
1176
	assert.ok( !method( "13:00 am" ), "Invalid time" );
1177
	assert.ok( !method( "00:00 am" ), "Invalid time" );
1178
} );
1179
 
1180
QUnit.test( "minWords", function( assert ) {
1181
	var method = methodTest( "minWords" );
1182
	assert.ok( method( "hello worlds", 2 ), "plain text, valid" );
1183
	assert.ok( method( "<b>hello</b> world", 2 ), "html, valid" );
1184
	assert.ok( !method( "hello", 2 ), "plain text, invalid" );
1185
	assert.ok( !method( "<b>world</b>", 2 ), "html, invalid" );
1186
	assert.ok( !method( "world <br/>", 2 ), "html, invalid" );
1187
} );
1188
 
1189
QUnit.test( "maxWords", function( assert ) {
1190
	var method = methodTest( "maxWords" );
1191
	assert.ok( method( "hello", 2 ), "plain text, valid" );
1192
	assert.ok( method( "<b>world</b>", 2 ), "html, valid" );
1193
	assert.ok( method( "world <br/>", 2 ), "html, valid" );
1194
	assert.ok( method( "hello worlds", 2 ), "plain text, valid" );
1195
	assert.ok( method( "<b>hello</b> world", 2 ), "html, valid" );
1196
	assert.ok( !method( "hello 123 world", 2 ), "plain text, invalid" );
1197
	assert.ok( !method( "<b>hello</b> 123 world", 2 ), "html, invalid" );
1198
} );
1199
 
1200
QUnit.test( "rangeWords", function( assert ) {
1201
	var method = methodTest( "rangeWords" );
1202
	assert.ok( method( "hello", [ 0, 2 ] ), "plain text, valid" );
1203
	assert.ok( method( "hello worlds", [ 0, 2 ] ), "plain text, valid" );
1204
	assert.ok( method( "<b>hello</b> world", [ 0, 2 ] ), "html, valid" );
1205
	assert.ok( !method( "hello worlds what is up", [ 0, 2 ] ), "plain text, invalid" );
1206
	assert.ok( !method( "<b>Hello</b> <b>world</b> <b>hello</b>", [ 0, 2 ] ), "html, invalid" );
1207
} );
1208
 
1209
QUnit.test( "pattern", function( assert ) {
1210
	var method = methodTest( "pattern" );
1211
	assert.ok( method( "AR1004", "AR\\d{4}" ), "Correct format for the given RegExp" );
1212
	assert.ok( method( "AR1004", /^AR\d{4}$/ ), "Correct format for the given RegExp" );
1213
	assert.ok( !method( "BR1004", /^AR\d{4}$/ ), "Invalid format for the given RegExp" );
1214
	assert.ok( method( "1ABC", "[0-9][A-Z]{3}" ), "Correct format for the given RegExp" );
1215
	assert.ok( !method( "ABC", "[0-9][A-Z]{3}" ), "Invalid format for the given RegExp" );
1216
	assert.ok( !method( "1ABC DEF", "[0-9][A-Z]{3}" ), "Invalid format for the given RegExp" );
1217
	assert.ok( method( "1ABCdef", "[a-zA-Z0-9]+" ), "Correct format for the given RegExp" );
1218
	assert.ok( !method( "1ABC def", "[a-zA-Z0-9]+" ), "Invalid format for the given RegExp" );
1219
	assert.ok( method( "2014-10-02", "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ), "Correct format for the given RegExp" );
1220
	assert.ok( !method( "02-10-2014", "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ), "Invalid format for the given RegExp" );
1221
} );
1222
 
1223
function testCardTypeByNumber( assert, number, cardname, expected ) {
1224
	$( "#cardnumber" ).val( number );
1225
	var actual = $( "#ccform" ).valid();
1226
	assert.equal( actual, expected, $.validator.format( "Expect card number {0} to validate to {1}, actually validated to ", number, expected ) );
1227
}
1228
 
1229
QUnit.test( "creditcardtypes, all", function( assert ) {
1230
	$( "#ccform" ).validate( {
1231
		rules: {
1232
			cardnumber: {
1233
				creditcard: true,
1234
				creditcardtypes: {
1235
					all: true
1236
				}
1237
			}
1238
		}
1239
	} );
1240
 
1241
	testCardTypeByNumber( assert, "4111-1111-1111-1111", "VISA", true );
1242
	testCardTypeByNumber( assert, "2211-1111-1111-1114", "MasterCard", true );
1243
	testCardTypeByNumber( assert, "5111-1111-1111-1118", "MasterCard", true );
1244
	testCardTypeByNumber( assert, "6111-1111-1111-1116", "Discover", true );
1245
	testCardTypeByNumber( assert, "3400-0000-0000-009", "AMEX", true );
1246
 
1247
	testCardTypeByNumber( assert, "4111-1111-1111-1110", "VISA", false );
1248
	testCardTypeByNumber( assert, "5432-1111-1111-1111", "MasterCard", false );
1249
	testCardTypeByNumber( assert, "6611-6611-6611-6611", "Discover", false );
1250
	testCardTypeByNumber( assert, "3777-7777-7777-7777", "AMEX", false );
1251
} );
1252
 
1253
QUnit.test( "creditcardtypes, visa", function( assert ) {
1254
	$( "#ccform" ).validate( {
1255
		rules: {
1256
			cardnumber: {
1257
				creditcard: true,
1258
				creditcardtypes: {
1259
					visa: true
1260
				}
1261
			}
1262
		}
1263
	} );
1264
 
1265
	testCardTypeByNumber( assert, "4111-1111-1111-1111", "VISA", true );
1266
	testCardTypeByNumber( assert, "5111-1111-1111-1118", "MasterCard", false );
1267
	testCardTypeByNumber( assert, "6111-1111-1111-1116", "Discover", false );
1268
	testCardTypeByNumber( assert, "3400-0000-0000-009", "AMEX", false );
1269
} );
1270
 
1271
QUnit.test( "creditcardtypes, mastercard", function( assert ) {
1272
	$( "#ccform" ).validate( {
1273
		rules: {
1274
			cardnumber: {
1275
				creditcard: true,
1276
				creditcardtypes: {
1277
					mastercard: true
1278
				}
1279
			}
1280
		}
1281
	} );
1282
 
1283
	testCardTypeByNumber( assert, "2211-1111-1111-1114", "MasterCard", true );
1284
	testCardTypeByNumber( assert, "5111-1111-1111-1118", "MasterCard", true );
1285
	testCardTypeByNumber( assert, "6111-1111-1111-1116", "Discover", false );
1286
	testCardTypeByNumber( assert, "3400-0000-0000-009", "AMEX", false );
1287
	testCardTypeByNumber( assert, "4111-1111-1111-1111", "VISA", false );
1288
} );
1289
 
1290
function fillFormWithValuesAndExpect( assert, formSelector, inputValues, expected ) {
1291
	var i, actual;
1292
 
1293
	for ( i = 0; i < inputValues.length; i++ ) {
1294
		$( formSelector + " input:eq(" + i + ")" ).val( inputValues[ i ] );
1295
	}
1296
	actual = $( formSelector ).valid();
1297
	assert.equal( actual, expected, $.validator.format( "Filled inputs of form '{0}' with {1} values ({2})", formSelector, inputValues.length, inputValues.toString() ) );
1298
 
1299
}
1300
 
1301
QUnit.test( "require_from_group", function( assert ) {
1302
	$( "#productInfo" ).validate( {
1303
		rules: {
1304
			partnumber: { require_from_group: [ 2, ".productInfo" ] },
1305
			description: { require_from_group: [ 2, ".productInfo" ] },
1306
			discount: { require_from_group: [ 2, ".productInfo" ] }
1307
		}
1308
	} );
1309
 
1310
	fillFormWithValuesAndExpect( assert, "#productInfo", [], false );
1311
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123 ], false );
1312
	$( "#productInfo input[type='checkbox']" ).attr( "checked", "checked" );
1313
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123 ], true );
1314
	$( "#productInfo input[type='checkbox']" ).removeAttr( "checked" );
1315
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget" ], true );
1316
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "red" ], true );
1317
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "red" ], true );
1318
} );
1319
 
1320
QUnit.test( "require_from_group preserve other rules", function( assert ) {
1321
	$( "#productInfo" ).validate( {
1322
		rules: {
1323
			partnumber: { require_from_group: [ 2, ".productInfo" ] },
1324
			description: { require_from_group: [ 2, ".productInfo" ] },
1325
			color: { require_from_group: [ 2, ".productInfo" ] },
1326
			supplier: { required: true }
1327
		}
1328
	} );
1329
 
1330
	fillFormWithValuesAndExpect( assert, "#productInfo", [], false );
1331
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123 ], false );
1332
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget" ], false );
1333
	fillFormWithValuesAndExpect( assert, "#productInfo", [ "", "", "", "Acme" ], false );
1334
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "", "", "Acme" ], false );
1335
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "", "Acme" ], true );
1336
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "red", "Acme" ], true );
1337
} );
1338
 
1339
QUnit.test( "skip_or_fill_minimum", function( assert ) {
1340
	$( "#productInfo" ).validate( {
1341
		rules: {
1342
			partnumber:  { skip_or_fill_minimum: [ 2, ".productInfo" ] },
1343
			description: { skip_or_fill_minimum: [ 2, ".productInfo" ] },
1344
			color:       { skip_or_fill_minimum: [ 2, ".productInfo" ] }
1345
		}
1346
	} );
1347
 
1348
	fillFormWithValuesAndExpect( assert, "#productInfo", [], true );
1349
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123 ], false );
1350
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget" ], true );
1351
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "red" ], true );
1352
} );
1353
 
1354
QUnit.test( "skip_or_fill_minimum preserve other rules", function( assert ) {
1355
	$( "#productInfo" ).validate( {
1356
		rules: {
1357
			partnumber:  { skip_or_fill_minimum: [ 2, ".productInfo" ] },
1358
			description: { skip_or_fill_minimum: [ 2, ".productInfo" ] },
1359
			color:       { skip_or_fill_minimum: [ 2, ".productInfo" ] },
1360
			supplier: { required: true }
1361
		}
1362
	} );
1363
 
1364
	fillFormWithValuesAndExpect( assert, "#productInfo", [], false );
1365
	fillFormWithValuesAndExpect( assert, "#productInfo", [ "", "", "", "Acme" ], true );
1366
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "", "", "Acme" ], false );
1367
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "", "Acme" ], true );
1368
	fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "red", "Acme" ], true );
1369
} );
1370
 
1371
QUnit.test( "zipcodeUS", function( assert ) {
1372
	var method = methodTest( "zipcodeUS" );
1373
	assert.ok( method( "12345" ), "Valid zip" );
1374
	assert.ok( method( "12345-2345" ), "Valid zip" );
1375
	assert.ok( method( "90210-4567" ), "Valid zip" );
1376
	assert.ok( !method( "1" ), "Invalid zip" );
1377
	assert.ok( !method( "1234" ), "Invalid zip" );
1378
	assert.ok( !method( "123-23" ), "Invalid zip" );
1379
	assert.ok( !method( "12345-43" ), "Invalid zip" );
1380
	assert.ok( !method( "123456-7890" ), "Invalid zip" );
1381
} );
1382
 
1383
QUnit.test( "nifES", function( assert ) {
1384
	var method = methodTest( "nifES" );
1385
	assert.ok( method( "11441059P" ), "NIF valid" );
1386
	assert.ok( method( "80054306T" ), "NIF valid" );
1387
	assert.ok( method( "76048581R" ), "NIF valid" );
1388
	assert.ok( method( "28950849J" ), "NIF valid" );
1389
	assert.ok( method( "34048598L" ), "NIF valid" );
1390
	assert.ok( method( "28311529R" ), "NIF valid" );
1391
	assert.ok( method( "34673804Q" ), "NIF valid" );
1392
	assert.ok( method( "92133247P" ), "NIF valid" );
1393
	assert.ok( method( "77149717N" ), "NIF valid" );
1394
	assert.ok( method( "15762034L" ), "NIF valid" );
1395
	assert.ok( method( "05122654W" ), "NIF valid" );
1396
	assert.ok( method( "05122654w" ), "NIF valid: lower case" );
1397
	assert.ok( method( "M1503708Z" ), "NIF valid. Temporary foreign nif" );
1398
	assert.ok( !method( "1144105R" ), "NIF invalid: less than 8 digits without zero" );
1399
	assert.ok( !method( "11441059 R" ), "NIF invalid: white space" );
1400
	assert.ok( !method( "11441059" ), "NIF invalid: no letter" );
1401
	assert.ok( !method( "11441059PR" ), "NIF invalid: two letters" );
1402
	assert.ok( !method( "11440059R" ), "NIF invalid: wrong number" );
1403
	assert.ok( !method( "11441059S" ), "NIF invalid: wrong letter" );
1404
	assert.ok( !method( "114410598R" ), "NIF invalid: > 8 digits" );
1405
	assert.ok( !method( "11441059-R" ), "NIF invalid: dash" );
1406
	assert.ok( !method( "asdasdasd" ), "NIF invalid: all letters" );
1407
	assert.ok( !method( "11.144.059R" ), "NIF invalid: two dots" );
1408
	assert.ok( !method( "05.122.654R" ), "NIF invalid: starts with 0 and dots" );
1409
	assert.ok( !method( "5.122.654-R" ), "NIF invalid:  dots and dash" );
1410
	assert.ok( !method( "05.122.654-R" ), "NIF invalid: starts with zero and dot and dash" );
1411
} );
1412
 
1413
QUnit.test( "nieES", function( assert ) {
1414
	var method = methodTest( "nieES" );
1415
	assert.ok( method( "X0093999K" ), "NIE valid" );
1416
	assert.ok( method( "X1923000Q" ), "NIE valid" );
1417
	assert.ok( method( "Z9669587R" ), "NIE valid" );
1418
	assert.ok( method( "Z8945005B" ), "NIE valid" );
1419
	assert.ok( method( "Z6663465W" ), "NIE valid" );
1420
	assert.ok( method( "Y7875935J" ), "NIE valid" );
1421
	assert.ok( method( "X3390130E" ), "NIE valid" );
1422
	assert.ok( method( "Y7699182S" ), "NIE valid" );
1423
	assert.ok( method( "Y1524243R" ), "NIE valid" );
1424
	assert.ok( method( "X3744072V" ), "NIE valid" );
1425
	assert.ok( method( "X7436800A" ), "NIE valid" );
1426
	assert.ok( method( "X00002153Z" ), "NIE valid" );
1427
	assert.ok( method( "X02323232W" ), "NIE valid" );
1428
	assert.ok( method( "Z0569549M" ), "NIE valid" );
1429
	assert.ok( method( "X0479906B" ), "NIE valid" );
1430
	assert.ok( method( "y7875935j" ), "NIE valid: lower case" );
1431
 
1432
	assert.ok( !method( "X0093999 K" ), "NIE invalid: white space" );
1433
	assert.ok( !method( "X 0093999 K" ), "NIE invalid:  white space" );
1434
	assert.ok( !method( "11441059" ), "NIE invalid: no letter" );
1435
	assert.ok( !method( "11441059PR" ), "NIE invalid: two letters" );
1436
	assert.ok( !method( "11440059R" ), "NIE invalid: wrong number" );
1437
	assert.ok( !method( "11441059S" ), "NIE invalid: wrong letter" );
1438
	assert.ok( !method( "114410598R" ), "NIE invalid: > 8 digits" );
1439
	assert.ok( !method( "11441059-R" ), "NIE invalid: dash" );
1440
	assert.ok( !method( "asdasdasd" ), "NIE invalid: all letters" );
1441
	assert.ok( !method( "11.144.059R" ), "NIE invalid: two dots" );
1442
	assert.ok( !method( "05.122.654R" ), "NIE invalid: starts with 0 and dots" );
1443
	assert.ok( !method( "5.122.654-R" ), "NIE invalid: dots and dash" );
1444
	assert.ok( !method( "05.122.654-R" ), "NIE invalid: starts with zero and dot and dash" );
1445
} );
1446
 
1447
QUnit.test( "cifES", function( assert ) {
1448
	var method = methodTest( "cifES" );
1449
	assert.ok( method( "A58818501" ), "CIF valid" );
1450
	assert.ok( method( "A79082244" ), "CIF valid" );
1451
	assert.ok( method( "A60917978" ), "CIF valid" );
1452
	assert.ok( method( "A39000013" ), "CIF valid" );
1453
	assert.ok( method( "A28315182" ), "CIF valid" );
1454
	assert.ok( method( "A75409573" ), "CIF valid" );
1455
	assert.ok( method( "A34396994" ), "CIF valid" );
1456
	assert.ok( method( "A08153538" ), "CIF valid" );
1457
	assert.ok( method( "A09681396" ), "CIF valid" );
1458
	assert.ok( method( "A06706303" ), "CIF valid" );
1459
	assert.ok( method( "A66242173" ), "CIF valid" );
1460
	assert.ok( method( "A61416699" ), "CIF valid" );
1461
	assert.ok( method( "A99545444" ), "CIF valid" );
1462
	assert.ok( method( "A10407252" ), "CIF valid" );
1463
	assert.ok( method( "A76170885" ), "CIF valid" );
1464
	assert.ok( method( "A83535047" ), "CIF valid" );
1465
	assert.ok( method( "A46031969" ), "CIF valid" );
1466
	assert.ok( method( "A97252910" ), "CIF valid" );
1467
	assert.ok( method( "A79082244" ), "CIF valid" );
1468
	assert.ok( !method( "A7908224D" ), "CIF invalid: digit control must be a number (4)" );
1469
 
1470
	assert.ok( method( "B71413892" ), "CIF valid" );
1471
	assert.ok( method( "B37484755" ), "CIF valid" );
1472
	assert.ok( method( "B15940893" ), "CIF valid" );
1473
	assert.ok( method( "B55429161" ), "CIF valid" );
1474
	assert.ok( method( "B93337087" ), "CIF valid" );
1475
	assert.ok( method( "B43522192" ), "CIF valid" );
1476
	assert.ok( method( "B38624334" ), "CIF valid" );
1477
	assert.ok( method( "B21920426" ), "CIF valid" );
1478
	assert.ok( method( "B74940156" ), "CIF valid" );
1479
	assert.ok( method( "B46125746" ), "CIF valid" );
1480
	assert.ok( method( "B67077537" ), "CIF valid" );
1481
	assert.ok( method( "B21283155" ), "CIF valid" );
1482
	assert.ok( method( "B57104176" ), "CIF valid" );
1483
	assert.ok( method( "B25060179" ), "CIF valid" );
1484
	assert.ok( method( "B06536338" ), "CIF valid" );
1485
	assert.ok( method( "B50964592" ), "CIF valid" );
1486
	assert.ok( method( "B15653330" ), "CIF valid" );
1487
	assert.ok( method( "B83524710" ), "CIF valid" );
1488
	assert.ok( !method( "B8352471J" ), "CIF invalid: digit control must be a number (0)" );
1489
 
1490
	assert.ok( !method( "C27827551" ), "CIF invalid: wrong digit control" );
1491
	assert.ok( !method( "C27827552" ), "CIF invalid: wrong digit control" );
1492
	assert.ok( !method( "C27827553" ), "CIF invalid: wrong digit control" );
1493
	assert.ok( !method( "C27827554" ), "CIF invalid: wrong digit control" );
1494
	assert.ok( !method( "C27827555" ), "CIF invalid: wrong digit control" );
1495
	assert.ok( !method( "C27827556" ), "CIF invalid: wrong digit control" );
1496
	assert.ok( !method( "C27827557" ), "CIF invalid: wrong digit control" );
1497
	assert.ok( !method( "C27827558" ), "CIF invalid: wrong digit control" );
1498
	assert.ok( !method( "C27827550" ), "CIF invalid: wrong digit control" );
1499
	assert.ok( !method( "C2782755A" ), "CIF invalid: wrong digit control" );
1500
	assert.ok( !method( "C2782755B" ), "CIF invalid: wrong digit control" );
1501
	assert.ok( !method( "C2782755C" ), "CIF invalid: wrong digit control" );
1502
	assert.ok( !method( "C2782755D" ), "CIF invalid: wrong digit control" );
1503
	assert.ok( !method( "C2782755E" ), "CIF invalid: wrong digit control" );
1504
	assert.ok( !method( "C2782755F" ), "CIF invalid: wrong digit control" );
1505
	assert.ok( !method( "C2782755G" ), "CIF invalid: wrong digit control" );
1506
	assert.ok( !method( "C2782755H" ), "CIF invalid: wrong digit control" );
1507
	assert.ok( !method( "C2782755J" ), "CIF invalid: wrong digit control" );
1508
	assert.ok( method( "C2782755I" ), "CIF valid. Digit control can be either a number or letter" );
1509
	assert.ok( method( "C27827559" ), "CIF valid. Digit control can be either a number or letter" );
1510
 
1511
	assert.ok( method( "E48911572" ), "CIF valid" );
1512
	assert.ok( method( "E93928703" ), "CIF valid" );
1513
	assert.ok( method( "E17472952" ), "CIF valid" );
1514
	assert.ok( !method( "E1747295B" ), "CIF invalid: digit control must be a number (2)" );
1515
 
1516
	assert.ok( method( "F41190612" ), "CIF valid" );
1517
	assert.ok( method( "F4119061B" ), "CIF valid. Digit control can be either a number or letter" );
1518
 
1519
	assert.ok( method( "G72102064" ), "CIF valid" );
1520
	assert.ok( method( "G32937757" ), "CIF valid" );
1521
	assert.ok( method( "G8984953C" ), "CIF valid" );
1522
	assert.ok( method( "G3370454E" ), "CIF valid" );
1523
	assert.ok( method( "G33704545" ), "CIF valid. Digit control can be either a number or letter" );
1524
 
1525
	assert.ok( method( "H48911572" ), "CIF valid" );
1526
	assert.ok( method( "H93928703" ), "CIF valid" );
1527
	assert.ok( method( "H17472952" ), "CIF valid" );
1528
	assert.ok( !method( "H1747295B" ), "CIF invalid: digit control must be a number (2)" );
1529
 
1530
	assert.ok( !method( "I48911572" ), "CIF invalid: starts with I" );
1531
 
1532
	assert.ok( method( "J85081081" ), "CIF valid" );
1533
	assert.ok( method( "J8508108A" ), "CIF valid" );
1534
 
1535
	assert.ok( method( "K3902238I" ), "CIF valid" );
1536
	assert.ok( !method( "K39022389" ), "CIF invalid. Digit control must be a letter (I)" );
1537
 
1538
	assert.ok( method( "M9916080F" ), "CIF valid" );
1539
	assert.ok( method( "M1566151E" ), "CIF valid" );
1540
	assert.ok( method( "M15661515" ), "CIF valid" );
1541
	assert.ok( method( "M4778730D" ), "CIF valid" );
1542
 
1543
	assert.ok( method( "N1172218H" ), "CIF valid" );
1544
	assert.ok( method( "N4094938J" ), "CIF valid" );
1545
	assert.ok( method( "N40949380" ), "CIF valid. Digit control can be either a number or letter" );
1546
 
1547
	assert.ok( method( "P5141387J" ), "CIF valid" );
1548
	assert.ok( method( "P9803881C" ), "CIF valid" );
1549
	assert.ok( !method( "P98038813" ), "CIF invalid: digit control must be a letter (C)" );
1550
 
1551
	assert.ok( method( "Q5141387J" ), "CIF valid" );
1552
	assert.ok( method( "Q9803881C" ), "CIF valid" );
1553
	assert.ok( !method( "Q98038813" ), "CIF invalid: digit control must be a letter (C)" );
1554
 
1555
	assert.ok( method( "S5141387J" ), "CIF valid" );
1556
	assert.ok( method( "S9803881C" ), "CIF valid" );
1557
	assert.ok( !method( "S98038813" ), "CIF invalid: digit control must be a letter (C)" );
1558
	assert.ok( method( "s98038813" ), "CIF valid: lower case" );
1559
 
1560
	assert.ok( !method( "X48911572" ), "CIF invalid: starts with X" );
1561
	assert.ok( !method( "Y48911572" ), "CIF invalid: starts with Y" );
1562
	assert.ok( !method( "Z48911572" ), "CIF invalid: starts with Z" );
1563
	assert.ok( !method( "Z98038813" ), "CIF invalid: wrong letter" );
1564
	assert.ok( !method( "B 43522192" ), "CIF invalid: white spaces" );
1565
	assert.ok( !method( "43522192" ), "CIF invalid: missing letter" );
1566
	assert.ok( !method( "BB43522192" ), "CIF invalid: two letters" );
1567
	assert.ok( !method( "B53522192" ), "CIF invalid: wrong number" );
1568
	assert.ok( !method( "B433522192" ), "CIF invalid: > 8 digits" );
1569
	assert.ok( !method( "B3522192" ), "CIF invalid: < 8 digits" );
1570
	assert.ok( !method( "B-43522192" ), "CIF invalid: dash" );
1571
	assert.ok( !method( "Basdasdas" ), "CIF invalid: all letters" );
1572
	assert.ok( !method( "B43.522.192" ), "CIF invalid: dots" );
1573
	assert.ok( !method( "B-43.522.192" ), "CIF invalid: dots and dash" );
1574
} );
1575
 
1576
QUnit.test( "nipPL", function( assert ) {
1577
	var method = methodTest( "nipPL" );
1578
	assert.ok( method( "3514242002" ), "NIP valid" );
1579
	assert.ok( method( "8117892840" ), "NIP valid" );
1580
	assert.ok( method( "7249598309" ), "NIP valid" );
1581
	assert.ok( method( "6853539166" ), "NIP valid" );
1582
	assert.ok( method( "5715750580" ), "NIP valid" );
1583
	assert.ok( method( "3496120813" ), "NIP valid" );
1584
	assert.ok( method( "1565710251" ), "NIP valid" );
1585
	assert.ok( method( "8190761165" ), "NIP valid" );
1586
	assert.ok( method( "9487499667" ), "NIP valid" );
1587
	assert.ok( method( "9283384684" ), "NIP valid" );
1588
	assert.ok( method( "3887569138" ), "NIP valid" );
1589
	assert.ok( method( "3962898856" ), "NIP valid" );
1590
	assert.ok( !method( "76355753" ), "NIP invalid: too short" );
1591
	assert.ok( !method( "454" ), "NIP invalid: too short" );
1592
	assert.ok( !method( "234565545" ), "NIP invalid: too short" );
1593
	assert.ok( !method( "543455" ), "NIP invalid: too short" );
1594
	assert.ok( !method( "6345634563456" ), "NIP invalid: too long" );
1595
	assert.ok( !method( "53453453455335" ), "NIP invalid: too long" );
1596
	assert.ok( !method( "543453760902" ), "NIP invalid: too long" );
1597
	assert.ok( !method( "43090012454" ), "NIP invalid: too long" );
1598
	assert.ok( !method( "3958250194" ), "NIP invalid: wrong checksum" );
1599
	assert.ok( !method( "3928541049" ), "NIP invalid: wrong checksum" );
1600
	assert.ok( !method( "5920397295" ), "NIP invalid: wrong checksum" );
1601
	assert.ok( !method( "9502947712" ), "NIP invalid: wrong checksum" );
1602
} );
1603
 
1604
QUnit.test( "phonePL", function( assert ) {
1605
    var method = methodTest( "phonePL" );
1606
	assert.ok( method( "+48 123 456 789" ), "Valid phone PL" );
1607
	assert.ok( method( "00 48 123 456 789" ), "Valid phone PL" );
1608
	assert.ok( method( "(+48) 123 456 789" ), "Valid phone PL" );
1609
	assert.ok( method( "(48) 123 456 789" ), "Valid phone PL" );
1610
	assert.ok( method( " 13 34 56 78  9 " ), "Valid phone PL" );
1611
	assert.ok( method( "13 345 67 89" ), "Valid phone PL" );
1612
	assert.ok( !method( "100 000 000" ), "Invalid phone PL: cannot start with 10x xxx xxx" );
1613
	assert.ok( !method( "111 111 111" ), "Invalid phone PL: cannot start with 11x xxx xxx" );
1614
	assert.ok( !method( "123 456 78" ), "Invalid phone PL: too short" );
1615
	assert.ok( !method( "123 4567890" ), "Invalid phone PL: too long" );
1616
	assert.ok( !method( "700 123 456" ), "Invalid phone PL: intelligent network, premium rate" );
1617
	assert.ok( !method( "800 123 456" ), "Invalid phone PL: intelligent network, freephone" );
1618
	assert.ok( !method( "980 000 000" ), "Invalid phone PL: cannot start with 98x xxx xxx" );
1619
	assert.ok( !method( "990 000 000" ), "Invalid phone PL: cannot start with 99x xxx xxx" );
1620
} );
1621
 
1622
QUnit.test( "maxWords", function( assert ) {
1623
	var method = methodTest( "maxWords" ),
1624
		maxWords = 6;
1625
 
1626
	assert.ok( method( "I am a sentence", maxWords ), "Max Words" );
1627
	assert.ok( !method( "I'm way too long for this sentence!", maxWords ), "Too many words" );
1628
	assert.ok( method( "Don’t “count” me as too long", maxWords ), "Right amount of words with smartquotes" );
1629
	assert.ok( !method( "But you can “count” me as too long", maxWords ), "Too many words with smartquotes" );
1630
	assert.ok( method( "<div>Don’t “count” me as too long</div>", maxWords ), "Right amount of words with smartquotes w/ HTML" );
1631
	assert.ok( !method( "<div>But you can “count” me as too long</div>", maxWords ), "Too many words with smartquotes w/ HTML" );
1632
} );
1633
 
1634
QUnit.test( "minWords", function( assert ) {
1635
	var method = methodTest( "minWords" ),
1636
		minWords = 6;
1637
 
1638
	assert.ok( !method( "I am a short sentence", minWords ), "Max Words" );
1639
	assert.ok( method( "I'm way too long for this sentence!", minWords ), "Too many words" );
1640
	assert.ok( !method( "Don’t “count” me as short.", minWords ), "Right amount of words with smartquotes" );
1641
	assert.ok( method( "But you can “count” me as too short", minWords ), "Too many words with smartquotes" );
1642
	assert.ok( !method( "<div>“Count” me as too short.</div>", minWords ), "Right amount of words with smartquotes w/ HTML" );
1643
	assert.ok( method( "<div>But you can “count” me as too long</div>", minWords ), "Too many words with smartquotes w/ HTML" );
1644
} );
1645
 
1646
QUnit.test( "rangeWords", function( assert ) {
1647
	var method = methodTest( "rangeWords" ),
1648
		rangeWords = [ 3, 6 ];
1649
 
1650
	assert.ok( !method( "I'm going to be longer than “six words!”", rangeWords ), "Longer than 6 with smartquotes" );
1651
	assert.ok( method( "I'm just the right amount!", rangeWords ), "In between" );
1652
	assert.ok( method( "Super short sentence’s.", rangeWords ), "Low end" );
1653
	assert.ok( !method( "I", rangeWords ), "Too short" );
1654
	assert.ok( method( "<div>“Count” me as perfect.</div>", rangeWords ), "Right amount of words with smartquotes w/ HTML" );
1655
	assert.ok( !method( "<div>But you can “count” me as too long</div>", rangeWords ), "Too many words with smartquotes w/ HTML" );
1656
} );
1657
 
1658
QUnit.test( "currency", function( assert ) { // Works with any symbol
1659
	var method = methodTest( "currency" );
1660
	assert.ok( method( "£9", "£" ), "Symbol no decimal" );
1661
	assert.ok( method( "£9.9", "£" ), "£, one decimal" );
1662
	assert.ok( method( "£9.99", "£" ), "£, two decimal" );
1663
	assert.ok( method( "£9.90", "£" ), "Valid currency" );
1664
	assert.ok( method( "£9,999.9", "£" ), "£, thousand, comma separator, one decimal" );
1665
	assert.ok( method( "£9,999.99", "£" ), "£, thousand, comma separator, two decimal" );
1666
	assert.ok( method( "£9,999,999.9", "£" ), "£, million, comma separators, one decimal" );
1667
	assert.ok( method( "9", [ "£", false ] ), "Valid currency" );
1668
	assert.ok( method( "9.9", [ "£", false ] ), "Valid currency" );
1669
	assert.ok( method( "9.99", [ "£", false ] ), "Valid currency" );
1670
	assert.ok( method( "9.90", [ "£", false ] ), "Valid currency" );
1671
	assert.ok( method( "9,999.9", [ "£", false ] ), "Valid currency" );
1672
	assert.ok( method( "9,999.99", [ "£", false ] ), "Valid currency" );
1673
	assert.ok( method( "9,999,999.9", [ "£", false ] ), "Valid currency" );
1674
	assert.ok( !method( "9,", "£" ), "Invalid currency" );
1675
	assert.ok( !method( "9,99.99", "£" ), "Invalid currency" );
1676
	assert.ok( !method( "9,", "£" ), "Invalid currency" );
1677
	assert.ok( !method( "9.999", "£" ), "Invalid currency" );
1678
	assert.ok( !method( "9.999", "£" ), "Invalid currency" );
1679
	assert.ok( !method( "9.99,9", "£" ), "Invalid currency" );
1680
} );
1681
 
1682
QUnit.test( "postalCodeCA", function( assert ) {
1683
	var method = methodTest( "postalCodeCA" );
1684
	assert.ok( method( "H0H0H0" ), "Valid Canadian postal code: all upper case with no space" );
1685
	assert.ok( method( "H0H 0H0" ), "Valid Canadian postal code: all upper case with one space" );
1686
	assert.ok( method( "H0H  0H0" ), "Valid Canadian postal code: all upper case with multiple spaces" );
1687
	assert.ok( method( "h0h 0h0" ), "Valid Canadian postal code: all lower case with space" );
1688
	assert.ok( method( "h0h0h0" ), "Valid Canadian postal code: all lower case with no space" );
1689
	assert.ok( !method( "H0H-0H0" ), "Invalid Canadian postal code: dash used as separator" );
1690
	assert.ok( !method( "H0H 0H" ), "Invalid Canadian postal code: too short" );
1691
	assert.ok( !method( "Z0H 0H0" ), "Invalid Canadian postal code: only 'ABCEGHJKLMNPRSTVXY' are valid first characters for the Forward Sorting Area" );
1692
	assert.ok( !method( "H0D 0H0" ), "Invalid Canadian postal code: only 'ABCEGHJKLMNPRSTVWXYZ' are valid third characters for the Forward Sorting Area" );
1693
	assert.ok( !method( "H0H 0D0" ), "Invalid Canadian postal code: only 'ABCEGHJKLMNPRSTVWXYZ' are valid second characters for the Local Delivery Unit" );
1694
} );
1695
 
1696
QUnit.test( "stateUS", function( assert ) {
1697
	var method = methodTest( "stateUS" );
1698
	assert.ok( method( "AZ" ), "Valid US state" );
1699
	assert.ok( method( "OH" ), "Valid US state" );
1700
	assert.ok( method( "DC" ), "Valid US state" );
1701
	assert.ok( method( "PR", { includeTerritories: true } ), "Valid US territory" );
1702
	assert.ok( method( "AA", { includeMilitary: true } ), "Valid US military zone" );
1703
	assert.ok( method( "me", { caseSensitive: false } ), "Valid US state" );
1704
	assert.ok( !method( "az", { caseSensitive: true } ), "Must be capital letters" );
1705
	assert.ok( !method( "mp", { caseSensitive: false, includeTerritories: false } ), "US territories not allowed" );
1706
} );
1707
 
1708
QUnit.test( "postalcodeBR", function( assert ) {
1709
	var method = methodTest( "postalcodeBR" );
1710
	assert.ok( method( "99999-999" ), "Valid BR Postal Code" );
1711
	assert.ok( method( "99999999" ), "Valid BR Postal Code" );
1712
	assert.ok( method( "99.999-999" ), "Valid BR Postal Code" );
1713
	assert.ok( !method( "99.999999" ), "Invalid BR Postal Code" );
1714
} );
1715
 
1716
QUnit.test( "cpfBR", function( assert ) {
1717
	var method = methodTest( "cpfBR" );
1718
	assert.ok( method( "11144477735" ), "Valid CPF Number" );
1719
	assert.ok( method( "263.946.533-30" ), "Valid CPF Number" );
1720
	assert.ok( method( "325 861 044 47" ), "Valid CPF Number" );
1721
	assert.ok( method( "859-684-732-40" ), "Valid CPF Number" );
1722
	assert.ok( !method( "99999999999" ), "Invalid CPF Number: dump data" );
1723
	assert.ok( !method( "1114447773" ), "Invalid CPF Number: < 11 digits" );
1724
	assert.ok( !method( "111444777355" ), "Invalid CPF Number: > 11 digits" );
1725
	assert.ok( !method( "11144477715" ), "Invalid CPF Number: 1st check number failed" );
1726
	assert.ok( !method( "11144477737" ), "Invalid CPF Number: 2nd check number failed" );
1727
} );
1728
 
1729
QUnit.test( "cnpjBR", function( assert ) {
1730
	var method = methodTest( "cnpjBR" );
1731
	assert.ok( method( "18517604000175" ), "Valid CNPJ Number" );
1732
	assert.ok( method( "18.517.604/0001-75" ), "Valid CNPJ Number" );
1733
	assert.ok( method( "06994660000111" ), "Valid CNPJ Number" );
1734
	assert.ok( method( "06.994.660/0001-11" ), "Valid CNPJ Number" );
1735
	assert.ok( !method( "00000000000000" ), "Invalid CNPJ Number: dump data" );
1736
	assert.ok( !method( "11111111111111" ), "Invalid CNPJ Number: dump data" );
1737
	assert.ok( !method( "22222222222222" ), "Invalid CNPJ Number: dump data" );
1738
	assert.ok( !method( "99999999999999" ), "Invalid CNPJ Number: dump data" );
1739
	assert.ok( !method( "8517604000175" ), "Invalid CNPJ Number: < 14 digits" );
1740
	assert.ok( !method( "8.517.604/0001-75" ), "Invalid CNPJ Number: < 14 digits" );
1741
	assert.ok( !method( "1185176040001750" ), "Invalid CNPJ Number: > 14 digits" );
1742
	assert.ok( !method( "18.517.604/0001-750" ), "Invalid CNPJ Number: > 14 digits" );
1743
	assert.ok( !method( "18517604000174" ), "Invalid CNPJ Number" );
1744
	assert.ok( !method( "18.517.604/0001-74" ), "Invalid CNPJ Number" );
1745
	assert.ok( !method( "06994660000211" ), "Invalid CNPJ Number" );
1746
	assert.ok( !method( "06.994.660/0002-11" ), "Invalid CNPJ Number" );
1747
} );
1748
 
1749
QUnit.test( "nisBR", function( assert ) {
1750
	var method = methodTest( "nisBR" );
1751
	assert.ok( method( "10757995753" ), "Valid NIS/PIS Number" );
1752
	assert.ok( method( "107.57995.75-3" ), "Valid NIS/PIS Number" );
1753
	assert.ok( method( "107.579.957-53" ), "Valid NIS/PIS Number" );
1754
	assert.ok( method( "107-579-957-53" ), "Valid NIS/PIS Number" );
1755
	assert.ok( method( "107.579.957.5-3" ), "Valid NIS/PIS Number" );
1756
	assert.ok( !method( "99999999999" ), "Invalid NIS/PIS Number: dump data" );
1757
	assert.ok( !method( "1075799575" ), "Invalid  NIS/PIS Number: < 11 digits" );
1758
	assert.ok( !method( "111444777355" ), "Invalid NIS/PIS Number: > 11 digits" );
1759
	assert.ok( !method( "10757995752" ), "Invalid NIS/PIS Number: check number failed" );
1760
} );
1761
 
1762
QUnit.test( "file accept - image wildcard", function( assert ) {
1763
	var input = acceptFileDummyInput( "test.png", "image/png" ),
1764
		$form = $( "<form />" ),
1765
		proxy = $.proxy( $.validator.methods.accept, new $.validator( {}, $form[ 0 ] ), null, input, "image/*" );
1766
	assert.ok( proxy(), "the selected file for upload has specified mime type" );
1767
} );
1768
 
1769
QUnit.test( "file accept - specified mime type", function( assert ) {
1770
	var input = acceptFileDummyInput( "test.kml", "application/vnd.google-earth.kml+xml" ),
1771
		$form = $( "<form />" ),
1772
		proxy = $.proxy( $.validator.methods.accept, new $.validator( {}, $form[ 0 ] ), null, input, "application/vnd.google-earth.kml+xml" );
1773
	assert.ok( proxy(), "the selected file for upload has specified mime type" );
1774
} );
1775
 
1776
QUnit.test( "file accept - multiple mimetypes", function( assert ) {
1777
	var input = acceptFileDummyInput( "test.png", "image/png" ),
1778
		$form = $( "<form />" ),
1779
		proxy = $.proxy( $.validator.methods.accept, new $.validator( {}, $form[ 0 ] ), null, input, "image/png,video/jpeg" );
1780
	assert.ok( proxy(), "the selected file for upload has specified mime type" );
1781
} );
1782
 
1783
QUnit.test( "file accept - multiple mimetypes with wildcard", function( assert ) {
1784
	var input = acceptFileDummyInput( "test.mp3", "audio/mpeg" ),
1785
		$form = $( "<form />" ),
1786
		proxy = $.proxy( $.validator.methods.accept, new $.validator( {}, $form[ 0 ] ), null, input, "image/*,audio/*" );
1787
	assert.ok( proxy(), "the selected file for upload has specified mime type" );
1788
} );
1789
 
1790
QUnit.test( "file accept - invalid mime type", function( assert ) {
1791
	var input = acceptFileDummyInput( "test.kml", "foobar/vnd.google-earth.kml+xml" ),
1792
		$form = $( "<form />" ),
1793
		proxy = $.proxy( $.validator.methods.accept, new $.validator( {}, $form[ 0 ] ), null, input, "application/vnd.google-earth.kml+xml" );
1794
	assert.equal( proxy(), false, "the selected file for upload has invalid mime type" );
1795
} );
1796
 
1797
QUnit.test( "file size - below max", function( assert ) {
1798
	var input = acceptFileDummyInput( "test.png", "image/png" ),
1799
		$form = $( "<form />" ),
1800
		proxy = $.proxy( $.validator.methods.maxsize, new $.validator( {}, $form[ 0 ] ), null, input, "500001" );
1801
	assert.ok( proxy(), "the selected file for upload is smaller than max" );
1802
} );
1803
 
1804
QUnit.test( "file size - over max", function( assert ) {
1805
	var input = acceptFileDummyInput( "test.png", "image/png" ),
1806
		$form = $( "<form />" ),
1807
		proxy = $.proxy( $.validator.methods.maxsize, new $.validator( {}, $form[ 0 ] ), null, input, "500000" );
1808
	assert.equal( proxy(), false, "the selected file for upload is greater than max" );
1809
} );
1810
 
1811
QUnit.test( "file maxsize - valid size", function( assert ) {
1812
	var selectedFiles = [ { name: "test.jpg", size: 500000 } ],
1813
		input = fileDummyInput( selectedFiles ),
1814
		$form = $( "<form />" ),
1815
		proxy = $.proxy( $.validator.methods.maxsize, new $.validator( {}, $form[ 0 ] ), null, input, 500000 );
1816
	assert.ok( proxy(), "the size of the file does not exceed the maximum" );
1817
} );
1818
 
1819
QUnit.test( "file maxsize - valid size for each file", function( assert ) {
1820
	var selectedFiles = [ { name: "test1.jpg", size: 500000 }, { name: "test2.jpg", size: 500000 } ],
1821
		input = fileDummyInput( selectedFiles ),
1822
	$form = $( "<form />" ),
1823
		proxy = $.proxy( $.validator.methods.maxsize, new $.validator( {}, $form[ 0 ] ), null, input, 500000 );
1824
	assert.ok( proxy(), "the size of the each file does not exceed the maximum" );
1825
} );
1826
 
1827
QUnit.test( "file maxsize - too big", function( assert ) {
1828
	var selectedFiles = [ { name: "test.jpg", size: 500001 } ],
1829
		input = fileDummyInput( selectedFiles ),
1830
		$form = $( "<form />" ),
1831
		proxy = $.proxy( $.validator.methods.maxsize, new $.validator( {}, $form[ 0 ] ), null, input, 500000 );
1832
	assert.equal( proxy(), false, "the size of the file exceeds the maximum" );
1833
} );
1834
 
1835
QUnit.test( "file maxsize - second file too big", function( assert ) {
1836
	var selectedFiles = [ { name: "test1.jpg", size: 500000 }, { name: "test2.jpg", size: 500001 } ],
1837
		input = fileDummyInput( selectedFiles ),
1838
		$form = $( "<form />" ),
1839
		proxy = $.proxy( $.validator.methods.maxsize, new $.validator( {}, $form[ 0 ] ), null, input, 500000 );
1840
	assert.equal( proxy(), false, "the size of the second file exceeds the maximum" );
1841
} );
1842
 
1843
QUnit.test( "file maxsizetotal - valid size", function( assert ) {
1844
	var selectedFiles = [ { name: "test1.jpg", size: 250000 }, { name: "test2.jpg", size: 250000 } ],
1845
		input = fileDummyInput( selectedFiles ),
1846
		$form = $( "<form />" ),
1847
		proxy = $.proxy( $.validator.methods.maxsizetotal, new $.validator( {}, $form[ 0 ] ), null, input, 500000 );
1848
	assert.ok( proxy(), "the size of the files together does not exceed the maximum" );
1849
} );
1850
 
1851
QUnit.test( "file maxsizetotal - too big", function( assert ) {
1852
	var selectedFiles = [ { name: "test1.jpg", size: 250000 }, { name: "test2.jpg", size: 250001 } ],
1853
		input = fileDummyInput( selectedFiles ),
1854
		$form = $( "<form />" ),
1855
		proxy = $.proxy( $.validator.methods.maxsizetotal, new $.validator( {}, $form[ 0 ] ), null, input, 500000 );
1856
	assert.equal( proxy(), false, "the size of the files together exceeds the maximum" );
1857
} );
1858
 
1859
QUnit.test( "file maxfiles - valid number", function( assert ) {
1860
	var selectedFiles = [ { name: "test1.jpg", size: 500000 }, { name: "test2.jpg", size: 500000 } ],
1861
		input = fileDummyInput( selectedFiles ),
1862
		$form = $( "<form />" ),
1863
		proxy = $.proxy( $.validator.methods.maxfiles, new $.validator( {}, $form[ 0 ] ), null, input, 2 );
1864
	assert.ok( proxy(), "the number of files does not exceed the maximum" );
1865
} );
1866
 
1867
QUnit.test( "file maxfiles - too many", function( assert ) {
1868
	var selectedFiles = [ { name: "test1.jpg", size: 500000 }, { name: "test2.jpg", size: 500000 }, { name: "test3.jpg", size: 500000 } ],
1869
		input = fileDummyInput( selectedFiles ),
1870
		$form = $( "<form />" ),
1871
		proxy = $.proxy( $.validator.methods.maxfiles, new $.validator( {}, $form[ 0 ] ), null, input, 2 );
1872
	assert.equal( proxy(), false, "the number of files exceeds the maximum" );
1873
} );