PageSourceSearch

https://dposs.ru/static/plugins/jquery-validate/additional-methods.js

js dposs.ru collected 2026-10-09 22:43:06 UTC 32,197 bytes, 857 lines download raw bytes

1/*!
2 * jQuery Validation Plugin v1.12.0
3 *
4 * http://jqueryvalidation.org/
5 *
6 * Copyright (c) 2014 Jörn Zaefferer
7 * Released under the MIT license
8 */
9(function() {
10
11	function stripHtml(value) {
12		// remove html tags and space chars
13		return value.replace(/<.[^<>]*?>/g, " ").replace(/&nbsp;|&#160;/gi, " ")
14		// remove punctuation
15		.replace(/[.(),;:!?%#$'\"_+=\/\-“”’]*/g, "");
16	}
17
18	jQuery.validator.addMethod("maxWords", function(value, element, params) {
19		return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length <= params;
20	}, jQuery.validator.format("Please enter {0} words or less."));
21
22	jQuery.validator.addMethod("minWords", function(value, element, params) {
23		return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length >= params;
24	}, jQuery.validator.format("Please enter at least {0} words."));
25
26	jQuery.validator.addMethod("rangeWords", function(value, element, params) {
27		var valueStripped = stripHtml(value),
28			regex = /\b\w+\b/g;
29		return this.optional(element) || valueStripped.match(regex).length >= params[0] && valueStripped.match(regex).length <= params[1];
30	}, jQuery.validator.format("Please enter between {0} and {1} words."));
31
32}());
33
34// Accept a value from a file input based on a required mimetype
35jQuery.validator.addMethod("accept", function(value, element, param) {
36	// Split mime on commas in case we have multiple types we can accept
37	var typeParam = typeof param === "string" ? param.replace(/\s/g, "").replace(/,/g, "|") : "image/*",
38	optionalValue = this.optional(element),
39	i, file;
40
41	// Element is optional
42	if (optionalValue) {
43		return optionalValue;
44	}
45
46	if (jQuery(element).attr("type") === "file") {
47		// If we are using a wildcard, make it regex friendly
48		typeParam = typeParam.replace(/\*/g, ".*");
49
50		// Check if the element has a FileList before checking each file
51		if (element.files && element.files.length) {
52			for (i = 0; i < element.files.length; i++) {
53				file = element.files[i];
54
55				// Grab the mimetype from the loaded file, verify it matches
56				if (!file.type.match(new RegExp( ".?(" + typeParam + ")$", "i"))) {
57					return false;
58				}
59			}
60		}
61	}
62
63	// Either return true because we've validated each file, or because the
64	// browser does not support element.files and the FileList feature
65	return true;
66}, jQuery.validator.format("Please enter a value with a valid mimetype."));
67
68jQuery.validator.addMethod("alphanumeric", function(value, element) {
69	return this.optional(element) || /^\w+$/i.test(value);
70}, "Letters, numbers, and underscores only please");
71
72/*
73 * Dutch bank account numbers (not 'giro' numbers) have 9 digits
74 * and pass the '11 check'.
75 * We accept the notation with spaces, as that is common.
76 * acceptable: 123456789 or 12 34 56 789
77 */
78jQuery.validator.addMethod("bankaccountNL", function(value, element) {
79	if (this.optional(element)) {
80		return true;
81	}
82	if (!(/^[0-9]{9}|([0-9]{2} ){3}[0-9]{3}$/.test(value))) {
83		return false;
84	}
85	// now '11 check'
86	var account = value.replace(/ /g, ""), // remove spaces
87		sum = 0,
88		len = account.length,
89		pos, factor, digit;
90	for ( pos = 0; pos < len; pos++ ) {
91		factor = len - pos;
92		digit = account.substring(pos, pos + 1);
93		sum = sum + factor * digit;
94	}
95	return sum % 11 === 0;
96}, "Please specify a valid bank account number");
97
98jQuery.validator.addMethod("bankorgiroaccountNL", function(value, element) {
99	return this.optional(element) ||
100			($.validator.methods.bankaccountNL.call(this, value, element)) ||
101			($.validator.methods.giroaccountNL.call(this, value, element));
102}, "Please specify a valid bank or giro account number");
103
104/**
105 * BIC is the business identifier code (ISO 9362). This BIC check is not a guarantee for authenticity.
106 *
107 * BIC pattern: BBBBCCLLbbb (8 or 11 characters long; bbb is optional)
108 *
109 * BIC definition in detail:
110 * - First 4 characters - bank code (only letters)
111 * - Next 2 characters - ISO 3166-1 alpha-2 country code (only letters)
112 * - Next 2 characters - location code (letters and digits)
113 *   a. shall not start with '0' or '1'
114 *   b. second character must be a letter ('O' is not allowed) or one of the following digits ('0' for test (therefore not allowed), '1' for passive participant and '2' for active participant)
115 * - Last 3 characters - branch code, optional (shall not start with 'X' except in case of 'XXX' for primary office) (letters and digits)
116 */
117jQuery.validator.addMethod("bic", function(value, element) {
118    return this.optional( element ) || /^([A-Z]{6}[A-Z2-9][A-NP-Z1-2])(X{3}|[A-WY-Z0-9][A-Z0-9]{2})?$/.test( value );
119}, "Please specify a valid BIC code");
120
121/*
122 * Código de identificación fiscal ( CIF ) is the tax identification code for Spanish legal entities
123 * Further rules can be found in Spanish on http://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal
124 */
125jQuery.validator.addMethod( "cifES", function( value ) {
126	"use strict";
127
128	var num = [],
129		controlDigit, sum, i, count, tmp, secondDigit;
130
131	value = value.toUpperCase();
132
133	// Quick format test
134	if ( !value.match( "((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)" ) ) {
135		return false;
136	}
137
138	for ( i = 0; i < 9; i++ ) {
139		num[ i ] = parseInt( value.charAt( i ), 10 );
140	}
141
142	// Algorithm for checking CIF codes
143	sum = num[ 2 ] + num[ 4 ] + num[ 6 ];
144	for ( count = 1; count < 8; count += 2 ) {
145		tmp = ( 2 * num[ count ] ).toString();
146		secondDigit = tmp.charAt( 1 );
147
148		sum += parseInt( tmp.charAt( 0 ), 10 ) + ( secondDigit === "" ? 0 : parseInt( secondDigit, 10 ) );
149	}
150
151	/* The first (position 1) is a letter following the following criteria:
152	 *	A. Corporations
153	 *	B. LLCs
154	 *	C. General partnerships
155	 *	D. Companies limited partnerships
156	 *	E. Communities of goods
157	 *	F. Cooperative Societies
158	 *	G. Associations
159	 *	H. Communities of homeowners in horizontal property regime
160	 *	J. Civil Societies
161	 *	K. Old format
162	 *	L. Old format
163	 *	M. Old format
164	 *	N. Nonresident entities
165	 *	P. Local authorities
166	 *	Q. Autonomous bodies, state or not, and the like, and congregations and religious institutions
167	 *	R. Congregations and religious institutions (since 2008 ORDER EHA/451/2008)
168	 *	S. Organs of State Administration and regions
169	 *	V. Agrarian Transformation
170	 *	W. Permanent establishments of non-resident in Spain
171	 */
172	if ( /^[ABCDEFGHJNPQRSUVW]{1}/.test( value ) ) {
173		sum += "";
174		controlDigit = 10 - parseInt( sum.charAt( sum.length - 1 ), 10 );
175		value += controlDigit;
176		return ( num[ 8 ].toString() === String.fromCharCode( 64 + controlDigit ) || num[ 8 ].toString() === value.charAt( value.length - 1 ) );
177	}
178
179	return false;
180
181}, "Please specify a valid CIF number." );
182
183/* NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator
184 * Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0
185 * Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings)
186 */
187jQuery.validator.addMethod("creditcardtypes", function(value, element, param) {
188	if (/[^0-9\-]+/.test(value)) {
189		return false;
190	}
191
192	value = value.replace(/\D/g, "");
193
194	var validTypes = 0x0000;
195
196	if (param.mastercard) {
197		validTypes |= 0x0001;
198	}
199	if (param.visa) {
200		validTypes |= 0x0002;
201	}
202	if (param.amex) {
203		validTypes |= 0x0004;
204	}
205	if (param.dinersclub) {
206		validTypes |= 0x0008;
207	}
208	if (param.enroute) {
209		validTypes |= 0x0010;
210	}
211	if (param.discover) {
212		validTypes |= 0x0020;
213	}
214	if (param.jcb) {
215		validTypes |= 0x0040;
216	}
217	if (param.unknown) {
218		validTypes |= 0x0080;
219	}
220	if (param.all) {
221		validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080;
222	}
223	if (validTypes & 0x0001 && /^(5[12345])/.test(value)) { //mastercard
224		return value.length === 16;
225	}
226	if (validTypes & 0x0002 && /^(4)/.test(value)) { //visa
227		return value.length === 16;
228	}
229	if (validTypes & 0x0004 && /^(3[47])/.test(value)) { //amex
230		return value.length === 15;
231	}
232	if (validTypes & 0x0008 && /^(3(0[012345]|[68]))/.test(value)) { //dinersclub
233		return value.length === 14;
234	}
235	if (validTypes & 0x0010 && /^(2(014|149))/.test(value)) { //enroute
236		return value.length === 15;
237	}
238	if (validTypes & 0x0020 && /^(6011)/.test(value)) { //discover
239		return value.length === 16;
240	}
241	if (validTypes & 0x0040 && /^(3)/.test(value)) { //jcb
242		return value.length === 16;
243	}
244	if (validTypes & 0x0040 && /^(2131|1800)/.test(value)) { //jcb
245		return value.length === 15;
246	}
247	if (validTypes & 0x0080) { //unknown
248		return true;
249	}
250	return false;
251}, "Please enter a valid credit card number.");
252
253/**
254 * Validates currencies with any given symbols by @jameslouiz
255 * Symbols can be optional or required. Symbols required by default
256 *
257 * Usage examples:
258 *  currency: ["£", false] - Use false for soft currency validation
259 *  currency: ["$", false]
260 *  currency: ["RM", false] - also works with text based symbols such as "RM" - Malaysia Ringgit etc
261 *
262 *  <input class="currencyInput" name="currencyInput">
263 *
264 * Soft symbol checking
265 *  currencyInput: {
266 *     currency: ["$", false]
267 *  }
268 *
269 * Strict symbol checking (default)
270 *  currencyInput: {
271 *     currency: "$"
272 *     //OR
273 *     currency: ["$", true]
274 *  }
275 *
276 * Multiple Symbols
277 *  currencyInput: {
278 *     currency: "$,£,¢"
279 *  }
280 */
281jQuery.validator.addMethod("currency", function(value, element, param) {
282    var isParamString = typeof param === "string",
283        symbol = isParamString ? param : param[0],
284        soft = isParamString ? true : param[1],
285        regex;
286
287    symbol = symbol.replace(/,/g, "");
288    symbol = soft ? symbol + "]" : symbol + "]?";
289    regex = "^[" + symbol + "([1-9]{1}[0-9]{0,2}(\\,[0-9]{3})*(\\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\\.[0-9]{0,2})?|0(\\.[0-9]{0,2})?|(\\.[0-9]{1,2})?)$";
290    regex = new RegExp(regex);
291    return this.optional(element) || regex.test(value);
292
293}, "Please specify a valid currency");
294
295/**
296 * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy.
297 *
298 * @example jQuery.validator.methods.date("01/01/1900")
299 * @result true
300 *
301 * @example jQuery.validator.methods.date("01/13/1990")
302 * @result false
303 *
304 * @example jQuery.validator.methods.date("01.01.1900")
305 * @result false
306 *
307 * @example <input name="pippo" class="{dateITA:true}" />
308 * @desc Declares an optional input element whose value must be a valid date.
309 *
310 * @name jQuery.validator.methods.dateITA
311 * @type Boolean
312 * @cat Plugins/Validate/Methods
313 */
314jQuery.validator.addMethod("dateITA", function(value, element) {
315	var check = false,
316		re = /^\d{1,2}\/\d{1,2}\/\d{4}$/,
317		adata, gg, mm, aaaa, xdata;
318	if ( re.test(value)) {
319		adata = value.split("/");
320		gg = parseInt(adata[0],10);
321		mm = parseInt(adata[1],10);
322		aaaa = parseInt(adata[2],10);
323		xdata = new Date(aaaa, mm - 1, gg, 12, 0, 0, 0);
324		if ( ( xdata.getFullYear() === aaaa ) && ( xdata.getMonth() === mm - 1 ) && ( xdata.getDate() === gg ) ){
325			check = true;
326		} else {
327			check = false;
vendor: 19,412 bytes, lines 328-786
328		}
329	} else {
330		check = false;
331	}
332	return this.optional(element) || check;
333}, "Please enter a correct date");
334
335jQuery.validator.addMethod("dateNL", function(value, element) {
336	return this.optional(element) || /^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test(value);
337}, "Please enter a correct date");
338
339// Older "accept" file extension method. Old docs: http://docs.jquery.com/Plugins/Validation/Methods/accept
340jQuery.validator.addMethod("extension", function(value, element, param) {
341	param = typeof param === "string" ? param.replace(/,/g, "|") : "png|jpe?g|gif";
342	return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i"));
343}, jQuery.validator.format("Please enter a value with a valid extension."));
344
345/**
346 * Dutch giro account numbers (not bank numbers) have max 7 digits
347 */
348jQuery.validator.addMethod("giroaccountNL", function(value, element) {
349	return this.optional(element) || /^[0-9]{1,7}$/.test(value);
350}, "Please specify a valid giro account number");
351
352/**
353 * IBAN is the international bank account number.
354 * It has a country - specific format, that is checked here too
355 */
356jQuery.validator.addMethod("iban", function(value, element) {
357	// some quick simple tests to prevent needless work
358	if (this.optional(element)) {
359		return true;
360	}
361
362	// remove spaces and to upper case
363	var iban = value.replace(/ /g,"").toUpperCase(),
364		ibancheckdigits = "",
365		leadingZeroes = true,
366		cRest = "",
367		cOperator = "",
368		countrycode, ibancheck, charAt, cChar, bbanpattern, bbancountrypatterns, ibanregexp, i, p;
369
370	if (!(/^([a-zA-Z0-9]{4} ){2,8}[a-zA-Z0-9]{1,4}|[a-zA-Z0-9]{12,34}$/.test(iban))) {
371		return false;
372	}
373
374	// check the country code and find the country specific format
375	countrycode = iban.substring(0,2);
376	bbancountrypatterns = {
377		"AL": "\\d{8}[\\dA-Z]{16}",
378		"AD": "\\d{8}[\\dA-Z]{12}",
379		"AT": "\\d{16}",
380		"AZ": "[\\dA-Z]{4}\\d{20}",
381		"BE": "\\d{12}",
382		"BH": "[A-Z]{4}[\\dA-Z]{14}",
383		"BA": "\\d{16}",
384		"BR": "\\d{23}[A-Z][\\dA-Z]",
385		"BG": "[A-Z]{4}\\d{6}[\\dA-Z]{8}",
386		"CR": "\\d{17}",
387		"HR": "\\d{17}",
388		"CY": "\\d{8}[\\dA-Z]{16}",
389		"CZ": "\\d{20}",
390		"DK": "\\d{14}",
391		"DO": "[A-Z]{4}\\d{20}",
392		"EE": "\\d{16}",
393		"FO": "\\d{14}",
394		"FI": "\\d{14}",
395		"FR": "\\d{10}[\\dA-Z]{11}\\d{2}",
396		"GE": "[\\dA-Z]{2}\\d{16}",
397		"DE": "\\d{18}",
398		"GI": "[A-Z]{4}[\\dA-Z]{15}",
399		"GR": "\\d{7}[\\dA-Z]{16}",
400		"GL": "\\d{14}",
401		"GT": "[\\dA-Z]{4}[\\dA-Z]{20}",
402		"HU": "\\d{24}",
403		"IS": "\\d{22}",
404		"IE": "[\\dA-Z]{4}\\d{14}",
405		"IL": "\\d{19}",
406		"IT": "[A-Z]\\d{10}[\\dA-Z]{12}",
407		"KZ": "\\d{3}[\\dA-Z]{13}",
408		"KW": "[A-Z]{4}[\\dA-Z]{22}",
409		"LV": "[A-Z]{4}[\\dA-Z]{13}",
410		"LB": "\\d{4}[\\dA-Z]{20}",
411		"LI": "\\d{5}[\\dA-Z]{12}",
412		"LT": "\\d{16}",
413		"LU": "\\d{3}[\\dA-Z]{13}",
414		"MK": "\\d{3}[\\dA-Z]{10}\\d{2}",
415		"MT": "[A-Z]{4}\\d{5}[\\dA-Z]{18}",
416		"MR": "\\d{23}",
417		"MU": "[A-Z]{4}\\d{19}[A-Z]{3}",
418		"MC": "\\d{10}[\\dA-Z]{11}\\d{2}",
419		"MD": "[\\dA-Z]{2}\\d{18}",
420		"ME": "\\d{18}",
421		"NL": "[A-Z]{4}\\d{10}",
422		"NO": "\\d{11}",
423		"PK": "[\\dA-Z]{4}\\d{16}",
424		"PS": "[\\dA-Z]{4}\\d{21}",
425		"PL": "\\d{24}",
426		"PT": "\\d{21}",
427		"RO": "[A-Z]{4}[\\dA-Z]{16}",
428		"SM": "[A-Z]\\d{10}[\\dA-Z]{12}",
429		"SA": "\\d{2}[\\dA-Z]{18}",
430		"RS": "\\d{18}",
431		"SK": "\\d{20}",
432		"SI": "\\d{15}",
433		"ES": "\\d{20}",
434		"SE": "\\d{20}",
435		"CH": "\\d{5}[\\dA-Z]{12}",
436		"TN": "\\d{20}",
437		"TR": "\\d{5}[\\dA-Z]{17}",
438		"AE": "\\d{3}\\d{16}",
439		"GB": "[A-Z]{4}\\d{14}",
440		"VG": "[\\dA-Z]{4}\\d{16}"
441	};
442
443	bbanpattern = bbancountrypatterns[countrycode];
444	// As new countries will start using IBAN in the
445	// future, we only check if the countrycode is known.
446	// This prevents false negatives, while almost all
447	// false positives introduced by this, will be caught
448	// by the checksum validation below anyway.
449	// Strict checking should return FALSE for unknown
450	// countries.
451	if (typeof bbanpattern !== "undefined") {
452		ibanregexp = new RegExp("^[A-Z]{2}\\d{2}" + bbanpattern + "$", "");
453		if (!(ibanregexp.test(iban))) {
454			return false; // invalid country specific format
455		}
456	}
457
458	// now check the checksum, first convert to digits
459	ibancheck = iban.substring(4,iban.length) + iban.substring(0,4);
460	for (i = 0; i < ibancheck.length; i++) {
461		charAt = ibancheck.charAt(i);
462		if (charAt !== "0") {
463			leadingZeroes = false;
464		}
465		if (!leadingZeroes) {
466			ibancheckdigits += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(charAt);
467		}
468	}
469
470	// calculate the result of: ibancheckdigits % 97
471	for (p = 0; p < ibancheckdigits.length; p++) {
472		cChar = ibancheckdigits.charAt(p);
473		cOperator = "" + cRest + "" + cChar;
474		cRest = cOperator % 97;
475	}
476	return cRest === 1;
477}, "Please specify a valid IBAN");
478
479jQuery.validator.addMethod("integer", function(value, element) {
480	return this.optional(element) || /^-?\d+$/.test(value);
481}, "A positive or negative non-decimal number please");
482
483jQuery.validator.addMethod("ipv4", function(value, element) {
484	return this.optional(element) || /^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/i.test(value);
485}, "Please enter a valid IP v4 address.");
486
487jQuery.validator.addMethod("ipv6", function(value, element) {
488	return this.optional(element) || /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i.test(value);
489}, "Please enter a valid IP v6 address.");
490
491jQuery.validator.addMethod("lettersonly", function(value, element) {
492	return this.optional(element) || /^[a-z]+$/i.test(value);
493}, "Letters only please");
494
495jQuery.validator.addMethod("letterswithbasicpunc", function(value, element) {
496	return this.optional(element) || /^[a-z\-.,()'"\s]+$/i.test(value);
497}, "Letters or punctuation only please");
498
499jQuery.validator.addMethod("mobileNL", function(value, element) {
500	return this.optional(element) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)6((\s|\s?\-\s?)?[0-9]){8}$/.test(value);
501}, "Please specify a valid mobile number");
502
503/* For UK phone functions, do the following server side processing:
504 * Compare original input with this RegEx pattern:
505 * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
506 * Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
507 * Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
508 * A number of very detailed GB telephone number RegEx patterns can also be found at:
509 * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
510 */
511jQuery.validator.addMethod("mobileUK", function(phone_number, element) {
512	phone_number = phone_number.replace(/\(|\)|\s+|-/g, "");
513	return this.optional(element) || phone_number.length > 9 &&
514		phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/);
515}, "Please specify a valid mobile number");
516
517/*
518 * The número de identidad de extranjero ( NIE )is a code used to identify the non-nationals in Spain
519 */
520jQuery.validator.addMethod( "nieES", function( value ) {
521	"use strict";
522
523	value = value.toUpperCase();
524
525	// Basic format test
526	if ( !value.match( "((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)" ) ) {
527		return false;
528	}
529
530	// Test NIE
531	//T
532	if ( /^[T]{1}/.test( value ) ) {
533		return ( value[ 8 ] === /^[T]{1}[A-Z0-9]{8}$/.test( value ) );
534	}
535
536	//XYZ
537	if ( /^[XYZ]{1}/.test( value ) ) {
538		return (
539			value[ 8 ] === "TRWAGMYFPDXBNJZSQVHLCKE".charAt(
540				value.replace( "X", "0" )
541					.replace( "Y", "1" )
542					.replace( "Z", "2" )
543					.substring( 0, 8 ) % 23
544			)
545		);
546	}
547
548	return false;
549
550}, "Please specify a valid NIE number." );
551
552/*
553 * The Número de Identificación Fiscal ( NIF ) is the way tax identification used in Spain for individuals
554 */
555jQuery.validator.addMethod( "nifES", function( value ) {
556	"use strict";
557
558	value = value.toUpperCase();
559
560	// Basic format test
561	if ( !value.match("((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)") ) {
562		return false;
563	}
564
565	// Test NIF
566	if ( /^[0-9]{8}[A-Z]{1}$/.test( value ) ) {
567		return ( "TRWAGMYFPDXBNJZSQVHLCKE".charAt( value.substring( 8, 0 ) % 23 ) === value.charAt( 8 ) );
568	}
569	// Test specials NIF (starts with K, L or M)
570	if ( /^[KLM]{1}/.test( value ) ) {
571		return ( value[ 8 ] === String.fromCharCode( 64 ) );
572	}
573
574	return false;
575
576}, "Please specify a valid NIF number." );
577
578jQuery.validator.addMethod("nowhitespace", function(value, element) {
579	return this.optional(element) || /^\S+$/i.test(value);
580}, "No white space please");
581
582/**
583* Return true if the field value matches the given format RegExp
584*
585* @example jQuery.validator.methods.pattern("AR1004",element,/^AR\d{4}$/)
586* @result true
587*
588* @example jQuery.validator.methods.pattern("BR1004",element,/^AR\d{4}$/)
589* @result false
590*
591* @name jQuery.validator.methods.pattern
592* @type Boolean
593* @cat Plugins/Validate/Methods
594*/
595jQuery.validator.addMethod("pattern", function(value, element, param) {
596	if (this.optional(element)) {
597		return true;
598	}
599	if (typeof param === "string") {
600		param = new RegExp(param);
601	}
602	return param.test(value);
603}, "Invalid format.");
604
605/**
606 * Dutch phone numbers have 10 digits (or 11 and start with +31).
607 */
608jQuery.validator.addMethod("phoneNL", function(value, element) {
609	return this.optional(element) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[1-9]((\s|\s?\-\s?)?[0-9]){8}$/.test(value);
610}, "Please specify a valid phone number.");
611
612/* For UK phone functions, do the following server side processing:
613 * Compare original input with this RegEx pattern:
614 * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
615 * Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
616 * Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
617 * A number of very detailed GB telephone number RegEx patterns can also be found at:
618 * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
619 */
620jQuery.validator.addMethod("phoneUK", function(phone_number, element) {
621	phone_number = phone_number.replace(/\(|\)|\s+|-/g, "");
622	return this.optional(element) || phone_number.length > 9 &&
623		phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:\d{2}\)?\s?\d{4}\s?\d{4}|\d{3}\)?\s?\d{3}\s?\d{3,4}|\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3})|\d{5}\)?\s?\d{4,5})$/);
624}, "Please specify a valid phone number");
625
626/**
627 * matches US phone number format
628 *
629 * where the area code may not start with 1 and the prefix may not start with 1
630 * allows '-' or ' ' as a separator and allows parens around area code
631 * some people may want to put a '1' in front of their number
632 *
633 * 1(212)-999-2345 or
634 * 212 999 2344 or
635 * 212-999-0983
636 *
637 * but not
638 * 111-123-5434
639 * and not
640 * 212 123 4567
641 */
642jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
643	phone_number = phone_number.replace(/\s+/g, "");
644	return this.optional(element) || phone_number.length > 9 &&
645		phone_number.match(/^(\+?1-?)?(\([2-9]([02-9]\d|1[02-9])\)|[2-9]([02-9]\d|1[02-9]))-?[2-9]([02-9]\d|1[02-9])-?\d{4}$/);
646}, "Please specify a valid phone number");
647
648/* For UK phone functions, do the following server side processing:
649 * Compare original input with this RegEx pattern:
650 * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
651 * Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
652 * Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
653 * A number of very detailed GB telephone number RegEx patterns can also be found at:
654 * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
655 */
656//Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers
657jQuery.validator.addMethod("phonesUK", function(phone_number, element) {
658	phone_number = phone_number.replace(/\(|\)|\s+|-/g, "");
659	return this.optional(element) || phone_number.length > 9 &&
660		phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/);
661}, "Please specify a valid uk phone number");
662
663jQuery.validator.addMethod("postalcodeNL", function(value, element) {
664	return this.optional(element) || /^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/.test(value);
665}, "Please specify a valid postal code");
666
667// Matches UK postcode. Does not match to UK Channel Islands that have their own postcodes (non standard UK)
668jQuery.validator.addMethod("postcodeUK", function(value, element) {
669	return this.optional(element) || /^((([A-PR-UWYZ][0-9])|([A-PR-UWYZ][0-9][0-9])|([A-PR-UWYZ][A-HK-Y][0-9])|([A-PR-UWYZ][A-HK-Y][0-9][0-9])|([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))\s?([0-9][ABD-HJLNP-UW-Z]{2})|(GIR)\s?(0AA))$/i.test(value);
670}, "Please specify a valid UK postcode");
671
672/*
673 * Lets you say "at least X inputs that match selector Y must be filled."
674 *
675 * The end result is that neither of these inputs:
676 *
677 *	<input class="productinfo" name="partnumber">
678 *	<input class="productinfo" name="description">
679 *
680 *	...will validate unless at least one of them is filled.
681 *
682 * partnumber:	{require_from_group: [1,".productinfo"]},
683 * description: {require_from_group: [1,".productinfo"]}
684 *
685 * options[0]: number of fields that must be filled in the group
686 * options[1]: CSS selector that defines the group of conditionally required fields
687 */
688jQuery.validator.addMethod("require_from_group", function(value, element, options) {
689	var $fields = $(options[1], element.form),
690		$fieldsFirst = $fields.eq(0),
691		validator = $fieldsFirst.data("valid_req_grp") ? $fieldsFirst.data("valid_req_grp") : $.extend({}, this),
692		isValid = $fields.filter(function() {
693			return validator.elementValue(this);
694		}).length >= options[0];
695
696	// Store the cloned validator for future validation
697	$fieldsFirst.data("valid_req_grp", validator);
698
699	// If element isn't being validated, run each require_from_group field's validation rules
700	if (!$(element).data("being_validated")) {
701		$fields.data("being_validated", true);
702		$fields.each(function() {
703			validator.element(this);
704		});
705		$fields.data("being_validated", false);
706	}
707	return isValid;
708}, jQuery.validator.format("Please fill at least {0} of these fields."));
709
710/*
711 * Lets you say "either at least X inputs that match selector Y must be filled,
712 * OR they must all be skipped (left blank)."
713 *
714 * The end result, is that none of these inputs:
715 *
716 *	<input class="productinfo" name="partnumber">
717 *	<input class="productinfo" name="description">
718 *	<input class="productinfo" name="color">
719 *
720 *	...will validate unless either at least two of them are filled,
721 *	OR none of them are.
722 *
723 * partnumber:	{skip_or_fill_minimum: [2,".productinfo"]},
724 * description: {skip_or_fill_minimum: [2,".productinfo"]},
725 * color:		{skip_or_fill_minimum: [2,".productinfo"]}
726 *
727 * options[0]: number of fields that must be filled in the group
728 * options[1]: CSS selector that defines the group of conditionally required fields
729 *
730 */
731jQuery.validator.addMethod("skip_or_fill_minimum", function(value, element, options) {
732	var $fields = $(options[1], element.form),
733		$fieldsFirst = $fields.eq(0),
734		validator = $fieldsFirst.data("valid_skip") ? $fieldsFirst.data("valid_skip") : $.extend({}, this),
735		numberFilled = $fields.filter(function() {
736			return validator.elementValue(this);
737		}).length,
738		isValid = numberFilled === 0 || numberFilled >= options[0];
739
740	// Store the cloned validator for future validation
741	$fieldsFirst.data("valid_skip", validator);
742
743	// If element isn't being validated, run each skip_or_fill_minimum field's validation rules
744	if (!$(element).data("being_validated")) {
745		$fields.data("being_validated", true);
746		$fields.each(function() {
747			validator.element(this);
748		});
749		$fields.data("being_validated", false);
750	}
751	return isValid;
752}, jQuery.validator.format("Please either skip these fields or fill at least {0} of them."));
753
754// TODO check if value starts with <, otherwise don't try stripping anything
755jQuery.validator.addMethod("strippedminlength", function(value, element, param) {
756	return jQuery(value).text().length >= param;
757}, jQuery.validator.format("Please enter at least {0} characters"));
758
759jQuery.validator.addMethod("time", function(value, element) {
760	return this.optional(element) || /^([01]\d|2[0-3])(:[0-5]\d){1,2}$/.test(value);
761}, "Please enter a valid time, between 00:00 and 23:59");
762
763jQuery.validator.addMethod("time12h", function(value, element) {
764	return this.optional(element) || /^((0?[1-9]|1[012])(:[0-5]\d){1,2}(\ ?[AP]M))$/i.test(value);
765}, "Please enter a valid time in 12-hour am/pm format");
766
767// same as url, but TLD is optional
768jQuery.validator.addMethod("url2", function(value, element) {
769	return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
770}, jQuery.validator.messages.url);
771
772/**
773 * Return true, if the value is a valid vehicle identification number (VIN).
774 *
775 * Works with all kind of text inputs.
776 *
777 * @example <input type="text" size="20" name="VehicleID" class="{required:true,vinUS:true}" />
778 * @desc Declares a required input element whose value must be a valid vehicle identification number.
779 *
780 * @name jQuery.validator.methods.vinUS
781 * @type Boolean
782 * @cat Plugins/Validate/Methods
783 */
784jQuery.validator.addMethod("vinUS", function(v) {
785	if (v.length !== 17) {
786		return false;
787	}
788
789	var LL = [ "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ],
790		VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ],
791		FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ],
792		rs = 0,
793		i, n, d, f, cd, cdv;
794
795	for (i = 0; i < 17; i++){
796		f = FL[i];
797		d = v.slice(i,i + 1);
798		if (i === 8) {
799			cdv = d;
800		}
801		if (!isNaN(d)) {
802			d *= f;
803		} else {
804			for (n = 0; n < LL.length; n++) {
805				if (d.toUpperCase() === LL[n]) {
806					d = VL[n];
807					d *= f;
808					if (isNaN(cdv) && n === 8) {
809						cdv = LL[n];
810					}
811					break;
812				}
813			}
814		}
815		rs += d;
816	}
817	cd = rs % 11;
818	if (cd === 10) {
819		cd = "X";
820	}
821	if (cd === cdv) {
822		return true;
823	}
824	return false;
825}, "The specified vehicle identification number (VIN) is invalid.");
826
827jQuery.validator.addMethod("zipcodeUS", function(value, element) {
828	return this.optional(element) || /^\d{5}-\d{4}$|^\d{5}$/.test(value);
829}, "The specified US ZIP Code is invalid");
830
831jQuery.validator.addMethod("ziprange", function(value, element) {
832	return this.optional(element) || /^90[2-5]\d\{2\}-\d{4}$/.test(value);
833}, "Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx");
834
835
836jQuery.validator.addMethod("uniqueEmail", function(value, element, url) {
837    var emailRequest = null;
838
839    function checkEmail(email, url){
840        var result = false;
841        if( emailRequest ) emailRequest.abort();
842        emailRequest = $.ajax({
843            url: url,
844            async: false,
845            type: 'POST',
846            data: {email: email},
847            success: function(response){
848                if( response == 'ok' ){
849                    result = true;
850                }
851            }
852        });
853        return result;
854    }
855
856    return checkEmail(value, url);
857}, 'Пользователь с таким email уже существует.');

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.