6056 |
efrain |
1 |
/*!
|
|
|
2 |
* jQuery Validation Plugin v1.15.0
|
|
|
3 |
*
|
|
|
4 |
* http://jqueryvalidation.org/
|
|
|
5 |
*
|
|
|
6 |
* Copyright (c) 2016 Jörn Zaefferer
|
|
|
7 |
* Released under the MIT license
|
|
|
8 |
*/
|
|
|
9 |
(function( factory ) {
|
|
|
10 |
if ( typeof define === "function" && define.amd ) {
|
|
|
11 |
define( ["jquery", "./jquery.validate"], factory );
|
|
|
12 |
} else if (typeof module === "object" && module.exports) {
|
|
|
13 |
module.exports = factory( require( "jquery" ) );
|
|
|
14 |
} else {
|
|
|
15 |
factory( jQuery );
|
|
|
16 |
}
|
|
|
17 |
}(function( $ ) {
|
|
|
18 |
|
|
|
19 |
( function() {
|
|
|
20 |
|
|
|
21 |
function stripHtml( value ) {
|
|
|
22 |
|
|
|
23 |
// Remove html tags and space chars
|
|
|
24 |
return value.replace( /<.[^<>]*?>/g, " " ).replace( / | /gi, " " )
|
|
|
25 |
|
|
|
26 |
// Remove punctuation
|
|
|
27 |
.replace( /[.(),;:!?%#$'\"_+=\/\-“”’]*/g, "" );
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
$.validator.addMethod( "maxWords", function( value, element, params ) {
|
|
|
31 |
return this.optional( element ) || stripHtml( value ).match( /\b\w+\b/g ).length <= params;
|
|
|
32 |
}, $.validator.format( "Please enter {0} words or less." ) );
|
|
|
33 |
|
|
|
34 |
$.validator.addMethod( "minWords", function( value, element, params ) {
|
|
|
35 |
return this.optional( element ) || stripHtml( value ).match( /\b\w+\b/g ).length >= params;
|
|
|
36 |
}, $.validator.format( "Please enter at least {0} words." ) );
|
|
|
37 |
|
|
|
38 |
$.validator.addMethod( "rangeWords", function( value, element, params ) {
|
|
|
39 |
var valueStripped = stripHtml( value ),
|
|
|
40 |
regex = /\b\w+\b/g;
|
|
|
41 |
return this.optional( element ) || valueStripped.match( regex ).length >= params[ 0 ] && valueStripped.match( regex ).length <= params[ 1 ];
|
|
|
42 |
}, $.validator.format( "Please enter between {0} and {1} words." ) );
|
|
|
43 |
|
|
|
44 |
}() );
|
|
|
45 |
|
|
|
46 |
// Accept a value from a file input based on a required mimetype
|
|
|
47 |
$.validator.addMethod( "accept", function( value, element, param ) {
|
|
|
48 |
|
|
|
49 |
// Split mime on commas in case we have multiple types we can accept
|
|
|
50 |
var typeParam = typeof param === "string" ? param.replace( /\s/g, "" ) : "image/*",
|
|
|
51 |
optionalValue = this.optional( element ),
|
|
|
52 |
i, file, regex;
|
|
|
53 |
|
|
|
54 |
// Element is optional
|
|
|
55 |
if ( optionalValue ) {
|
|
|
56 |
return optionalValue;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
if ( $( element ).attr( "type" ) === "file" ) {
|
|
|
60 |
|
|
|
61 |
// Escape string to be used in the regex
|
|
|
62 |
// see: http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
|
|
|
63 |
// Escape also "/*" as "/.*" as a wildcard
|
|
|
64 |
typeParam = typeParam.replace( /[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g, "\\$&" ).replace( /,/g, "|" ).replace( "\/*", "/.*" );
|
|
|
65 |
|
|
|
66 |
// Check if the element has a FileList before checking each file
|
|
|
67 |
if ( element.files && element.files.length ) {
|
|
|
68 |
regex = new RegExp( ".?(" + typeParam + ")$", "i" );
|
|
|
69 |
for ( i = 0; i < element.files.length; i++ ) {
|
|
|
70 |
file = element.files[ i ];
|
|
|
71 |
|
|
|
72 |
// Grab the mimetype from the loaded file, verify it matches
|
|
|
73 |
if ( !file.type.match( regex ) ) {
|
|
|
74 |
return false;
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
// Either return true because we've validated each file, or because the
|
|
|
81 |
// browser does not support element.files and the FileList feature
|
|
|
82 |
return true;
|
|
|
83 |
}, $.validator.format( "Please enter a value with a valid mimetype." ) );
|
|
|
84 |
|
|
|
85 |
$.validator.addMethod( "alphanumeric", function( value, element ) {
|
|
|
86 |
return this.optional( element ) || /^\w+$/i.test( value );
|
|
|
87 |
}, "Letters, numbers, and underscores only please" );
|
|
|
88 |
|
|
|
89 |
/*
|
|
|
90 |
* Dutch bank account numbers (not 'giro' numbers) have 9 digits
|
|
|
91 |
* and pass the '11 check'.
|
|
|
92 |
* We accept the notation with spaces, as that is common.
|
|
|
93 |
* acceptable: 123456789 or 12 34 56 789
|
|
|
94 |
*/
|
|
|
95 |
$.validator.addMethod( "bankaccountNL", function( value, element ) {
|
|
|
96 |
if ( this.optional( element ) ) {
|
|
|
97 |
return true;
|
|
|
98 |
}
|
|
|
99 |
if ( !( /^[0-9]{9}|([0-9]{2} ){3}[0-9]{3}$/.test( value ) ) ) {
|
|
|
100 |
return false;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
// Now '11 check'
|
|
|
104 |
var account = value.replace( / /g, "" ), // Remove spaces
|
|
|
105 |
sum = 0,
|
|
|
106 |
len = account.length,
|
|
|
107 |
pos, factor, digit;
|
|
|
108 |
for ( pos = 0; pos < len; pos++ ) {
|
|
|
109 |
factor = len - pos;
|
|
|
110 |
digit = account.substring( pos, pos + 1 );
|
|
|
111 |
sum = sum + factor * digit;
|
|
|
112 |
}
|
|
|
113 |
return sum % 11 === 0;
|
|
|
114 |
}, "Please specify a valid bank account number" );
|
|
|
115 |
|
|
|
116 |
$.validator.addMethod( "bankorgiroaccountNL", function( value, element ) {
|
|
|
117 |
return this.optional( element ) ||
|
|
|
118 |
( $.validator.methods.bankaccountNL.call( this, value, element ) ) ||
|
|
|
119 |
( $.validator.methods.giroaccountNL.call( this, value, element ) );
|
|
|
120 |
}, "Please specify a valid bank or giro account number" );
|
|
|
121 |
|
|
|
122 |
/**
|
|
|
123 |
* BIC is the business identifier code (ISO 9362). This BIC check is not a guarantee for authenticity.
|
|
|
124 |
*
|
|
|
125 |
* BIC pattern: BBBBCCLLbbb (8 or 11 characters long; bbb is optional)
|
|
|
126 |
*
|
|
|
127 |
* Validation is case-insensitive. Please make sure to normalize input yourself.
|
|
|
128 |
*
|
|
|
129 |
* BIC definition in detail:
|
|
|
130 |
* - First 4 characters - bank code (only letters)
|
|
|
131 |
* - Next 2 characters - ISO 3166-1 alpha-2 country code (only letters)
|
|
|
132 |
* - Next 2 characters - location code (letters and digits)
|
|
|
133 |
* a. shall not start with '0' or '1'
|
|
|
134 |
* b. second character must be a letter ('O' is not allowed) or digit ('0' for test (therefore not allowed), '1' denoting passive participant, '2' typically reverse-billing)
|
|
|
135 |
* - Last 3 characters - branch code, optional (shall not start with 'X' except in case of 'XXX' for primary office) (letters and digits)
|
|
|
136 |
*/
|
|
|
137 |
$.validator.addMethod( "bic", function( value, element ) {
|
|
|
138 |
return this.optional( element ) || /^([A-Z]{6}[A-Z2-9][A-NP-Z1-9])(X{3}|[A-WY-Z0-9][A-Z0-9]{2})?$/.test( value.toUpperCase() );
|
|
|
139 |
}, "Please specify a valid BIC code" );
|
|
|
140 |
|
|
|
141 |
/*
|
|
|
142 |
* Código de identificación fiscal ( CIF ) is the tax identification code for Spanish legal entities
|
|
|
143 |
* Further rules can be found in Spanish on http://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal
|
|
|
144 |
*/
|
|
|
145 |
$.validator.addMethod( "cifES", function( value ) {
|
|
|
146 |
"use strict";
|
|
|
147 |
|
|
|
148 |
var num = [],
|
|
|
149 |
controlDigit, sum, i, count, tmp, secondDigit;
|
|
|
150 |
|
|
|
151 |
value = value.toUpperCase();
|
|
|
152 |
|
|
|
153 |
// Quick format test
|
|
|
154 |
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}$)" ) ) {
|
|
|
155 |
return false;
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
for ( i = 0; i < 9; i++ ) {
|
|
|
159 |
num[ i ] = parseInt( value.charAt( i ), 10 );
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
// Algorithm for checking CIF codes
|
|
|
163 |
sum = num[ 2 ] + num[ 4 ] + num[ 6 ];
|
|
|
164 |
for ( count = 1; count < 8; count += 2 ) {
|
|
|
165 |
tmp = ( 2 * num[ count ] ).toString();
|
|
|
166 |
secondDigit = tmp.charAt( 1 );
|
|
|
167 |
|
|
|
168 |
sum += parseInt( tmp.charAt( 0 ), 10 ) + ( secondDigit === "" ? 0 : parseInt( secondDigit, 10 ) );
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
/* The first (position 1) is a letter following the following criteria:
|
|
|
172 |
* A. Corporations
|
|
|
173 |
* B. LLCs
|
|
|
174 |
* C. General partnerships
|
|
|
175 |
* D. Companies limited partnerships
|
|
|
176 |
* E. Communities of goods
|
|
|
177 |
* F. Cooperative Societies
|
|
|
178 |
* G. Associations
|
|
|
179 |
* H. Communities of homeowners in horizontal property regime
|
|
|
180 |
* J. Civil Societies
|
|
|
181 |
* K. Old format
|
|
|
182 |
* L. Old format
|
|
|
183 |
* M. Old format
|
|
|
184 |
* N. Nonresident entities
|
|
|
185 |
* P. Local authorities
|
|
|
186 |
* Q. Autonomous bodies, state or not, and the like, and congregations and religious institutions
|
|
|
187 |
* R. Congregations and religious institutions (since 2008 ORDER EHA/451/2008)
|
|
|
188 |
* S. Organs of State Administration and regions
|
|
|
189 |
* V. Agrarian Transformation
|
|
|
190 |
* W. Permanent establishments of non-resident in Spain
|
|
|
191 |
*/
|
|
|
192 |
if ( /^[ABCDEFGHJNPQRSUVW]{1}/.test( value ) ) {
|
|
|
193 |
sum += "";
|
|
|
194 |
controlDigit = 10 - parseInt( sum.charAt( sum.length - 1 ), 10 );
|
|
|
195 |
value += controlDigit;
|
|
|
196 |
return ( num[ 8 ].toString() === String.fromCharCode( 64 + controlDigit ) || num[ 8 ].toString() === value.charAt( value.length - 1 ) );
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
return false;
|
|
|
200 |
|
|
|
201 |
}, "Please specify a valid CIF number." );
|
|
|
202 |
|
|
|
203 |
/*
|
|
|
204 |
* Brazillian CPF number (Cadastrado de Pessoas Físicas) is the equivalent of a Brazilian tax registration number.
|
|
|
205 |
* CPF numbers have 11 digits in total: 9 numbers followed by 2 check numbers that are being used for validation.
|
|
|
206 |
*/
|
|
|
207 |
$.validator.addMethod( "cpfBR", function( value ) {
|
|
|
208 |
|
|
|
209 |
// Removing special characters from value
|
|
|
210 |
value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" );
|
|
|
211 |
|
|
|
212 |
// Checking value to have 11 digits only
|
|
|
213 |
if ( value.length !== 11 ) {
|
|
|
214 |
return false;
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
var sum = 0,
|
|
|
218 |
firstCN, secondCN, checkResult, i;
|
|
|
219 |
|
|
|
220 |
firstCN = parseInt( value.substring( 9, 10 ), 10 );
|
|
|
221 |
secondCN = parseInt( value.substring( 10, 11 ), 10 );
|
|
|
222 |
|
|
|
223 |
checkResult = function( sum, cn ) {
|
|
|
224 |
var result = ( sum * 10 ) % 11;
|
|
|
225 |
if ( ( result === 10 ) || ( result === 11 ) ) {
|
|
|
226 |
result = 0;
|
|
|
227 |
}
|
|
|
228 |
return ( result === cn );
|
|
|
229 |
};
|
|
|
230 |
|
|
|
231 |
// Checking for dump data
|
|
|
232 |
if ( value === "" ||
|
|
|
233 |
value === "00000000000" ||
|
|
|
234 |
value === "11111111111" ||
|
|
|
235 |
value === "22222222222" ||
|
|
|
236 |
value === "33333333333" ||
|
|
|
237 |
value === "44444444444" ||
|
|
|
238 |
value === "55555555555" ||
|
|
|
239 |
value === "66666666666" ||
|
|
|
240 |
value === "77777777777" ||
|
|
|
241 |
value === "88888888888" ||
|
|
|
242 |
value === "99999999999"
|
|
|
243 |
) {
|
|
|
244 |
return false;
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
// Step 1 - using first Check Number:
|
|
|
248 |
for ( i = 1; i <= 9; i++ ) {
|
|
|
249 |
sum = sum + parseInt( value.substring( i - 1, i ), 10 ) * ( 11 - i );
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
// If first Check Number (CN) is valid, move to Step 2 - using second Check Number:
|
|
|
253 |
if ( checkResult( sum, firstCN ) ) {
|
|
|
254 |
sum = 0;
|
|
|
255 |
for ( i = 1; i <= 10; i++ ) {
|
|
|
256 |
sum = sum + parseInt( value.substring( i - 1, i ), 10 ) * ( 12 - i );
|
|
|
257 |
}
|
|
|
258 |
return checkResult( sum, secondCN );
|
|
|
259 |
}
|
|
|
260 |
return false;
|
|
|
261 |
|
|
|
262 |
}, "Please specify a valid CPF number" );
|
|
|
263 |
|
|
|
264 |
// http://jqueryvalidation.org/creditcard-method/
|
|
|
265 |
// based on http://en.wikipedia.org/wiki/Luhn_algorithm
|
|
|
266 |
$.validator.addMethod( "creditcard", function( value, element ) {
|
|
|
267 |
if ( this.optional( element ) ) {
|
|
|
268 |
return "dependency-mismatch";
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
// Accept only spaces, digits and dashes
|
|
|
272 |
if ( /[^0-9 \-]+/.test( value ) ) {
|
|
|
273 |
return false;
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
var nCheck = 0,
|
|
|
277 |
nDigit = 0,
|
|
|
278 |
bEven = false,
|
|
|
279 |
n, cDigit;
|
|
|
280 |
|
|
|
281 |
value = value.replace( /\D/g, "" );
|
|
|
282 |
|
|
|
283 |
// Basing min and max length on
|
|
|
284 |
// http://developer.ean.com/general_info/Valid_Credit_Card_Types
|
|
|
285 |
if ( value.length < 13 || value.length > 19 ) {
|
|
|
286 |
return false;
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
for ( n = value.length - 1; n >= 0; n-- ) {
|
|
|
290 |
cDigit = value.charAt( n );
|
|
|
291 |
nDigit = parseInt( cDigit, 10 );
|
|
|
292 |
if ( bEven ) {
|
|
|
293 |
if ( ( nDigit *= 2 ) > 9 ) {
|
|
|
294 |
nDigit -= 9;
|
|
|
295 |
}
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
nCheck += nDigit;
|
|
|
299 |
bEven = !bEven;
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
return ( nCheck % 10 ) === 0;
|
|
|
303 |
}, "Please enter a valid credit card number." );
|
|
|
304 |
|
|
|
305 |
/* NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator
|
|
|
306 |
* Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0
|
|
|
307 |
* Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings)
|
|
|
308 |
*/
|
|
|
309 |
$.validator.addMethod( "creditcardtypes", function( value, element, param ) {
|
|
|
310 |
if ( /[^0-9\-]+/.test( value ) ) {
|
|
|
311 |
return false;
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
value = value.replace( /\D/g, "" );
|
|
|
315 |
|
|
|
316 |
var validTypes = 0x0000;
|
|
|
317 |
|
|
|
318 |
if ( param.mastercard ) {
|
|
|
319 |
validTypes |= 0x0001;
|
|
|
320 |
}
|
|
|
321 |
if ( param.visa ) {
|
|
|
322 |
validTypes |= 0x0002;
|
|
|
323 |
}
|
|
|
324 |
if ( param.amex ) {
|
|
|
325 |
validTypes |= 0x0004;
|
|
|
326 |
}
|
|
|
327 |
if ( param.dinersclub ) {
|
|
|
328 |
validTypes |= 0x0008;
|
|
|
329 |
}
|
|
|
330 |
if ( param.enroute ) {
|
|
|
331 |
validTypes |= 0x0010;
|
|
|
332 |
}
|
|
|
333 |
if ( param.discover ) {
|
|
|
334 |
validTypes |= 0x0020;
|
|
|
335 |
}
|
|
|
336 |
if ( param.jcb ) {
|
|
|
337 |
validTypes |= 0x0040;
|
|
|
338 |
}
|
|
|
339 |
if ( param.unknown ) {
|
|
|
340 |
validTypes |= 0x0080;
|
|
|
341 |
}
|
|
|
342 |
if ( param.all ) {
|
|
|
343 |
validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080;
|
|
|
344 |
}
|
|
|
345 |
if ( validTypes & 0x0001 && /^(5[12345])/.test( value ) ) { // Mastercard
|
|
|
346 |
return value.length === 16;
|
|
|
347 |
}
|
|
|
348 |
if ( validTypes & 0x0002 && /^(4)/.test( value ) ) { // Visa
|
|
|
349 |
return value.length === 16;
|
|
|
350 |
}
|
|
|
351 |
if ( validTypes & 0x0004 && /^(3[47])/.test( value ) ) { // Amex
|
|
|
352 |
return value.length === 15;
|
|
|
353 |
}
|
|
|
354 |
if ( validTypes & 0x0008 && /^(3(0[012345]|[68]))/.test( value ) ) { // Dinersclub
|
|
|
355 |
return value.length === 14;
|
|
|
356 |
}
|
|
|
357 |
if ( validTypes & 0x0010 && /^(2(014|149))/.test( value ) ) { // Enroute
|
|
|
358 |
return value.length === 15;
|
|
|
359 |
}
|
|
|
360 |
if ( validTypes & 0x0020 && /^(6011)/.test( value ) ) { // Discover
|
|
|
361 |
return value.length === 16;
|
|
|
362 |
}
|
|
|
363 |
if ( validTypes & 0x0040 && /^(3)/.test( value ) ) { // Jcb
|
|
|
364 |
return value.length === 16;
|
|
|
365 |
}
|
|
|
366 |
if ( validTypes & 0x0040 && /^(2131|1800)/.test( value ) ) { // Jcb
|
|
|
367 |
return value.length === 15;
|
|
|
368 |
}
|
|
|
369 |
if ( validTypes & 0x0080 ) { // Unknown
|
|
|
370 |
return true;
|
|
|
371 |
}
|
|
|
372 |
return false;
|
|
|
373 |
}, "Please enter a valid credit card number." );
|
|
|
374 |
|
|
|
375 |
/**
|
|
|
376 |
* Validates currencies with any given symbols by @jameslouiz
|
|
|
377 |
* Symbols can be optional or required. Symbols required by default
|
|
|
378 |
*
|
|
|
379 |
* Usage examples:
|
|
|
380 |
* currency: ["£", false] - Use false for soft currency validation
|
|
|
381 |
* currency: ["$", false]
|
|
|
382 |
* currency: ["RM", false] - also works with text based symbols such as "RM" - Malaysia Ringgit etc
|
|
|
383 |
*
|
|
|
384 |
* <input class="currencyInput" name="currencyInput">
|
|
|
385 |
*
|
|
|
386 |
* Soft symbol checking
|
|
|
387 |
* currencyInput: {
|
|
|
388 |
* currency: ["$", false]
|
|
|
389 |
* }
|
|
|
390 |
*
|
|
|
391 |
* Strict symbol checking (default)
|
|
|
392 |
* currencyInput: {
|
|
|
393 |
* currency: "$"
|
|
|
394 |
* //OR
|
|
|
395 |
* currency: ["$", true]
|
|
|
396 |
* }
|
|
|
397 |
*
|
|
|
398 |
* Multiple Symbols
|
|
|
399 |
* currencyInput: {
|
|
|
400 |
* currency: "$,£,¢"
|
|
|
401 |
* }
|
|
|
402 |
*/
|
|
|
403 |
$.validator.addMethod( "currency", function( value, element, param ) {
|
|
|
404 |
var isParamString = typeof param === "string",
|
|
|
405 |
symbol = isParamString ? param : param[ 0 ],
|
|
|
406 |
soft = isParamString ? true : param[ 1 ],
|
|
|
407 |
regex;
|
|
|
408 |
|
|
|
409 |
symbol = symbol.replace( /,/g, "" );
|
|
|
410 |
symbol = soft ? symbol + "]" : symbol + "]?";
|
|
|
411 |
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})?)$";
|
|
|
412 |
regex = new RegExp( regex );
|
|
|
413 |
return this.optional( element ) || regex.test( value );
|
|
|
414 |
|
|
|
415 |
}, "Please specify a valid currency" );
|
|
|
416 |
|
|
|
417 |
$.validator.addMethod( "dateFA", function( value, element ) {
|
|
|
418 |
return this.optional( element ) || /^[1-4]\d{3}\/((0?[1-6]\/((3[0-1])|([1-2][0-9])|(0?[1-9])))|((1[0-2]|(0?[7-9]))\/(30|([1-2][0-9])|(0?[1-9]))))$/.test( value );
|
|
|
419 |
}, $.validator.messages.date );
|
|
|
420 |
|
|
|
421 |
/**
|
|
|
422 |
* Return true, if the value is a valid date, also making this formal check dd/mm/yyyy.
|
|
|
423 |
*
|
|
|
424 |
* @example $.validator.methods.date("01/01/1900")
|
|
|
425 |
* @result true
|
|
|
426 |
*
|
|
|
427 |
* @example $.validator.methods.date("01/13/1990")
|
|
|
428 |
* @result false
|
|
|
429 |
*
|
|
|
430 |
* @example $.validator.methods.date("01.01.1900")
|
|
|
431 |
* @result false
|
|
|
432 |
*
|
|
|
433 |
* @example <input name="pippo" class="{dateITA:true}" />
|
|
|
434 |
* @desc Declares an optional input element whose value must be a valid date.
|
|
|
435 |
*
|
|
|
436 |
* @name $.validator.methods.dateITA
|
|
|
437 |
* @type Boolean
|
|
|
438 |
* @cat Plugins/Validate/Methods
|
|
|
439 |
*/
|
|
|
440 |
$.validator.addMethod( "dateITA", function( value, element ) {
|
|
|
441 |
var check = false,
|
|
|
442 |
re = /^\d{1,2}\/\d{1,2}\/\d{4}$/,
|
|
|
443 |
adata, gg, mm, aaaa, xdata;
|
|
|
444 |
if ( re.test( value ) ) {
|
|
|
445 |
adata = value.split( "/" );
|
|
|
446 |
gg = parseInt( adata[ 0 ], 10 );
|
|
|
447 |
mm = parseInt( adata[ 1 ], 10 );
|
|
|
448 |
aaaa = parseInt( adata[ 2 ], 10 );
|
|
|
449 |
xdata = new Date( Date.UTC( aaaa, mm - 1, gg, 12, 0, 0, 0 ) );
|
|
|
450 |
if ( ( xdata.getUTCFullYear() === aaaa ) && ( xdata.getUTCMonth() === mm - 1 ) && ( xdata.getUTCDate() === gg ) ) {
|
|
|
451 |
check = true;
|
|
|
452 |
} else {
|
|
|
453 |
check = false;
|
|
|
454 |
}
|
|
|
455 |
} else {
|
|
|
456 |
check = false;
|
|
|
457 |
}
|
|
|
458 |
return this.optional( element ) || check;
|
|
|
459 |
}, $.validator.messages.date );
|
|
|
460 |
|
|
|
461 |
$.validator.addMethod( "dateNL", function( value, element ) {
|
|
|
462 |
return this.optional( element ) || /^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test( value );
|
|
|
463 |
}, $.validator.messages.date );
|
|
|
464 |
|
|
|
465 |
// Older "accept" file extension method. Old docs: http://docs.jquery.com/Plugins/Validation/Methods/accept
|
|
|
466 |
$.validator.addMethod( "extension", function( value, element, param ) {
|
|
|
467 |
param = typeof param === "string" ? param.replace( /,/g, "|" ) : "png|jpe?g|gif";
|
|
|
468 |
return this.optional( element ) || value.match( new RegExp( "\\.(" + param + ")$", "i" ) );
|
|
|
469 |
}, $.validator.format( "Please enter a value with a valid extension." ) );
|
|
|
470 |
|
|
|
471 |
/**
|
|
|
472 |
* Dutch giro account numbers (not bank numbers) have max 7 digits
|
|
|
473 |
*/
|
|
|
474 |
$.validator.addMethod( "giroaccountNL", function( value, element ) {
|
|
|
475 |
return this.optional( element ) || /^[0-9]{1,7}$/.test( value );
|
|
|
476 |
}, "Please specify a valid giro account number" );
|
|
|
477 |
|
|
|
478 |
/**
|
|
|
479 |
* IBAN is the international bank account number.
|
|
|
480 |
* It has a country - specific format, that is checked here too
|
|
|
481 |
*
|
|
|
482 |
* Validation is case-insensitive. Please make sure to normalize input yourself.
|
|
|
483 |
*/
|
|
|
484 |
$.validator.addMethod( "iban", function( value, element ) {
|
|
|
485 |
|
|
|
486 |
// Some quick simple tests to prevent needless work
|
|
|
487 |
if ( this.optional( element ) ) {
|
|
|
488 |
return true;
|
|
|
489 |
}
|
|
|
490 |
|
|
|
491 |
// Remove spaces and to upper case
|
|
|
492 |
var iban = value.replace( / /g, "" ).toUpperCase(),
|
|
|
493 |
ibancheckdigits = "",
|
|
|
494 |
leadingZeroes = true,
|
|
|
495 |
cRest = "",
|
|
|
496 |
cOperator = "",
|
|
|
497 |
countrycode, ibancheck, charAt, cChar, bbanpattern, bbancountrypatterns, ibanregexp, i, p;
|
|
|
498 |
|
|
|
499 |
// Check the country code and find the country specific format
|
|
|
500 |
countrycode = iban.substring( 0, 2 );
|
|
|
501 |
bbancountrypatterns = {
|
|
|
502 |
"AL": "\\d{8}[\\dA-Z]{16}",
|
|
|
503 |
"AD": "\\d{8}[\\dA-Z]{12}",
|
|
|
504 |
"AT": "\\d{16}",
|
|
|
505 |
"AZ": "[\\dA-Z]{4}\\d{20}",
|
|
|
506 |
"BE": "\\d{12}",
|
|
|
507 |
"BH": "[A-Z]{4}[\\dA-Z]{14}",
|
|
|
508 |
"BA": "\\d{16}",
|
|
|
509 |
"BR": "\\d{23}[A-Z][\\dA-Z]",
|
|
|
510 |
"BG": "[A-Z]{4}\\d{6}[\\dA-Z]{8}",
|
|
|
511 |
"CR": "\\d{17}",
|
|
|
512 |
"HR": "\\d{17}",
|
|
|
513 |
"CY": "\\d{8}[\\dA-Z]{16}",
|
|
|
514 |
"CZ": "\\d{20}",
|
|
|
515 |
"DK": "\\d{14}",
|
|
|
516 |
"DO": "[A-Z]{4}\\d{20}",
|
|
|
517 |
"EE": "\\d{16}",
|
|
|
518 |
"FO": "\\d{14}",
|
|
|
519 |
"FI": "\\d{14}",
|
|
|
520 |
"FR": "\\d{10}[\\dA-Z]{11}\\d{2}",
|
|
|
521 |
"GE": "[\\dA-Z]{2}\\d{16}",
|
|
|
522 |
"DE": "\\d{18}",
|
|
|
523 |
"GI": "[A-Z]{4}[\\dA-Z]{15}",
|
|
|
524 |
"GR": "\\d{7}[\\dA-Z]{16}",
|
|
|
525 |
"GL": "\\d{14}",
|
|
|
526 |
"GT": "[\\dA-Z]{4}[\\dA-Z]{20}",
|
|
|
527 |
"HU": "\\d{24}",
|
|
|
528 |
"IS": "\\d{22}",
|
|
|
529 |
"IE": "[\\dA-Z]{4}\\d{14}",
|
|
|
530 |
"IL": "\\d{19}",
|
|
|
531 |
"IT": "[A-Z]\\d{10}[\\dA-Z]{12}",
|
|
|
532 |
"KZ": "\\d{3}[\\dA-Z]{13}",
|
|
|
533 |
"KW": "[A-Z]{4}[\\dA-Z]{22}",
|
|
|
534 |
"LV": "[A-Z]{4}[\\dA-Z]{13}",
|
|
|
535 |
"LB": "\\d{4}[\\dA-Z]{20}",
|
|
|
536 |
"LI": "\\d{5}[\\dA-Z]{12}",
|
|
|
537 |
"LT": "\\d{16}",
|
|
|
538 |
"LU": "\\d{3}[\\dA-Z]{13}",
|
|
|
539 |
"MK": "\\d{3}[\\dA-Z]{10}\\d{2}",
|
|
|
540 |
"MT": "[A-Z]{4}\\d{5}[\\dA-Z]{18}",
|
|
|
541 |
"MR": "\\d{23}",
|
|
|
542 |
"MU": "[A-Z]{4}\\d{19}[A-Z]{3}",
|
|
|
543 |
"MC": "\\d{10}[\\dA-Z]{11}\\d{2}",
|
|
|
544 |
"MD": "[\\dA-Z]{2}\\d{18}",
|
|
|
545 |
"ME": "\\d{18}",
|
|
|
546 |
"NL": "[A-Z]{4}\\d{10}",
|
|
|
547 |
"NO": "\\d{11}",
|
|
|
548 |
"PK": "[\\dA-Z]{4}\\d{16}",
|
|
|
549 |
"PS": "[\\dA-Z]{4}\\d{21}",
|
|
|
550 |
"PL": "\\d{24}",
|
|
|
551 |
"PT": "\\d{21}",
|
|
|
552 |
"RO": "[A-Z]{4}[\\dA-Z]{16}",
|
|
|
553 |
"SM": "[A-Z]\\d{10}[\\dA-Z]{12}",
|
|
|
554 |
"SA": "\\d{2}[\\dA-Z]{18}",
|
|
|
555 |
"RS": "\\d{18}",
|
|
|
556 |
"SK": "\\d{20}",
|
|
|
557 |
"SI": "\\d{15}",
|
|
|
558 |
"ES": "\\d{20}",
|
|
|
559 |
"SE": "\\d{20}",
|
|
|
560 |
"CH": "\\d{5}[\\dA-Z]{12}",
|
|
|
561 |
"TN": "\\d{20}",
|
|
|
562 |
"TR": "\\d{5}[\\dA-Z]{17}",
|
|
|
563 |
"AE": "\\d{3}\\d{16}",
|
|
|
564 |
"GB": "[A-Z]{4}\\d{14}",
|
|
|
565 |
"VG": "[\\dA-Z]{4}\\d{16}"
|
|
|
566 |
};
|
|
|
567 |
|
|
|
568 |
bbanpattern = bbancountrypatterns[ countrycode ];
|
|
|
569 |
|
|
|
570 |
// As new countries will start using IBAN in the
|
|
|
571 |
// future, we only check if the countrycode is known.
|
|
|
572 |
// This prevents false negatives, while almost all
|
|
|
573 |
// false positives introduced by this, will be caught
|
|
|
574 |
// by the checksum validation below anyway.
|
|
|
575 |
// Strict checking should return FALSE for unknown
|
|
|
576 |
// countries.
|
|
|
577 |
if ( typeof bbanpattern !== "undefined" ) {
|
|
|
578 |
ibanregexp = new RegExp( "^[A-Z]{2}\\d{2}" + bbanpattern + "$", "" );
|
|
|
579 |
if ( !( ibanregexp.test( iban ) ) ) {
|
|
|
580 |
return false; // Invalid country specific format
|
|
|
581 |
}
|
|
|
582 |
}
|
|
|
583 |
|
|
|
584 |
// Now check the checksum, first convert to digits
|
|
|
585 |
ibancheck = iban.substring( 4, iban.length ) + iban.substring( 0, 4 );
|
|
|
586 |
for ( i = 0; i < ibancheck.length; i++ ) {
|
|
|
587 |
charAt = ibancheck.charAt( i );
|
|
|
588 |
if ( charAt !== "0" ) {
|
|
|
589 |
leadingZeroes = false;
|
|
|
590 |
}
|
|
|
591 |
if ( !leadingZeroes ) {
|
|
|
592 |
ibancheckdigits += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf( charAt );
|
|
|
593 |
}
|
|
|
594 |
}
|
|
|
595 |
|
|
|
596 |
// Calculate the result of: ibancheckdigits % 97
|
|
|
597 |
for ( p = 0; p < ibancheckdigits.length; p++ ) {
|
|
|
598 |
cChar = ibancheckdigits.charAt( p );
|
|
|
599 |
cOperator = "" + cRest + "" + cChar;
|
|
|
600 |
cRest = cOperator % 97;
|
|
|
601 |
}
|
|
|
602 |
return cRest === 1;
|
|
|
603 |
}, "Please specify a valid IBAN" );
|
|
|
604 |
|
|
|
605 |
$.validator.addMethod( "integer", function( value, element ) {
|
|
|
606 |
return this.optional( element ) || /^-?\d+$/.test( value );
|
|
|
607 |
}, "A positive or negative non-decimal number please" );
|
|
|
608 |
|
|
|
609 |
$.validator.addMethod( "ipv4", function( value, element ) {
|
|
|
610 |
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 );
|
|
|
611 |
}, "Please enter a valid IP v4 address." );
|
|
|
612 |
|
|
|
613 |
$.validator.addMethod( "ipv6", function( value, element ) {
|
|
|
614 |
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 );
|
|
|
615 |
}, "Please enter a valid IP v6 address." );
|
|
|
616 |
|
|
|
617 |
$.validator.addMethod( "lettersonly", function( value, element ) {
|
|
|
618 |
return this.optional( element ) || /^[a-z]+$/i.test( value );
|
|
|
619 |
}, "Letters only please" );
|
|
|
620 |
|
|
|
621 |
$.validator.addMethod( "letterswithbasicpunc", function( value, element ) {
|
|
|
622 |
return this.optional( element ) || /^[a-z\-.,()'"\s]+$/i.test( value );
|
|
|
623 |
}, "Letters or punctuation only please" );
|
|
|
624 |
|
|
|
625 |
$.validator.addMethod( "mobileNL", function( value, element ) {
|
|
|
626 |
return this.optional( element ) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)6((\s|\s?\-\s?)?[0-9]){8}$/.test( value );
|
|
|
627 |
}, "Please specify a valid mobile number" );
|
|
|
628 |
|
|
|
629 |
/* For UK phone functions, do the following server side processing:
|
|
|
630 |
* Compare original input with this RegEx pattern:
|
|
|
631 |
* ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
|
|
|
632 |
* Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
|
|
|
633 |
* Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
|
|
|
634 |
* A number of very detailed GB telephone number RegEx patterns can also be found at:
|
|
|
635 |
* http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
|
|
|
636 |
*/
|
|
|
637 |
$.validator.addMethod( "mobileUK", function( phone_number, element ) {
|
|
|
638 |
phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );
|
|
|
639 |
return this.optional( element ) || phone_number.length > 9 &&
|
|
|
640 |
phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/ );
|
|
|
641 |
}, "Please specify a valid mobile number" );
|
|
|
642 |
|
|
|
643 |
/*
|
|
|
644 |
* The número de identidad de extranjero ( NIE )is a code used to identify the non-nationals in Spain
|
|
|
645 |
*/
|
|
|
646 |
$.validator.addMethod( "nieES", function( value ) {
|
|
|
647 |
"use strict";
|
|
|
648 |
|
|
|
649 |
value = value.toUpperCase();
|
|
|
650 |
|
|
|
651 |
// Basic format test
|
|
|
652 |
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}$)" ) ) {
|
|
|
653 |
return false;
|
|
|
654 |
}
|
|
|
655 |
|
|
|
656 |
// Test NIE
|
|
|
657 |
//T
|
|
|
658 |
if ( /^[T]{1}/.test( value ) ) {
|
|
|
659 |
return ( value[ 8 ] === /^[T]{1}[A-Z0-9]{8}$/.test( value ) );
|
|
|
660 |
}
|
|
|
661 |
|
|
|
662 |
//XYZ
|
|
|
663 |
if ( /^[XYZ]{1}/.test( value ) ) {
|
|
|
664 |
return (
|
|
|
665 |
value[ 8 ] === "TRWAGMYFPDXBNJZSQVHLCKE".charAt(
|
|
|
666 |
value.replace( "X", "0" )
|
|
|
667 |
.replace( "Y", "1" )
|
|
|
668 |
.replace( "Z", "2" )
|
|
|
669 |
.substring( 0, 8 ) % 23
|
|
|
670 |
)
|
|
|
671 |
);
|
|
|
672 |
}
|
|
|
673 |
|
|
|
674 |
return false;
|
|
|
675 |
|
|
|
676 |
}, "Please specify a valid NIE number." );
|
|
|
677 |
|
|
|
678 |
/*
|
|
|
679 |
* The Número de Identificación Fiscal ( NIF ) is the way tax identification used in Spain for individuals
|
|
|
680 |
*/
|
|
|
681 |
$.validator.addMethod( "nifES", function( value ) {
|
|
|
682 |
"use strict";
|
|
|
683 |
|
|
|
684 |
value = value.toUpperCase();
|
|
|
685 |
|
|
|
686 |
// Basic format test
|
|
|
687 |
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}$)" ) ) {
|
|
|
688 |
return false;
|
|
|
689 |
}
|
|
|
690 |
|
|
|
691 |
// Test NIF
|
|
|
692 |
if ( /^[0-9]{8}[A-Z]{1}$/.test( value ) ) {
|
|
|
693 |
return ( "TRWAGMYFPDXBNJZSQVHLCKE".charAt( value.substring( 8, 0 ) % 23 ) === value.charAt( 8 ) );
|
|
|
694 |
}
|
|
|
695 |
|
|
|
696 |
// Test specials NIF (starts with K, L or M)
|
|
|
697 |
if ( /^[KLM]{1}/.test( value ) ) {
|
|
|
698 |
return ( value[ 8 ] === String.fromCharCode( 64 ) );
|
|
|
699 |
}
|
|
|
700 |
|
|
|
701 |
return false;
|
|
|
702 |
|
|
|
703 |
}, "Please specify a valid NIF number." );
|
|
|
704 |
|
|
|
705 |
jQuery.validator.addMethod( "notEqualTo", function( value, element, param ) {
|
|
|
706 |
return this.optional( element ) || !$.validator.methods.equalTo.call( this, value, element, param );
|
|
|
707 |
}, "Please enter a different value, values must not be the same." );
|
|
|
708 |
|
|
|
709 |
$.validator.addMethod( "nowhitespace", function( value, element ) {
|
|
|
710 |
return this.optional( element ) || /^\S+$/i.test( value );
|
|
|
711 |
}, "No white space please" );
|
|
|
712 |
|
|
|
713 |
/**
|
|
|
714 |
* Return true if the field value matches the given format RegExp
|
|
|
715 |
*
|
|
|
716 |
* @example $.validator.methods.pattern("AR1004",element,/^AR\d{4}$/)
|
|
|
717 |
* @result true
|
|
|
718 |
*
|
|
|
719 |
* @example $.validator.methods.pattern("BR1004",element,/^AR\d{4}$/)
|
|
|
720 |
* @result false
|
|
|
721 |
*
|
|
|
722 |
* @name $.validator.methods.pattern
|
|
|
723 |
* @type Boolean
|
|
|
724 |
* @cat Plugins/Validate/Methods
|
|
|
725 |
*/
|
|
|
726 |
$.validator.addMethod( "pattern", function( value, element, param ) {
|
|
|
727 |
if ( this.optional( element ) ) {
|
|
|
728 |
return true;
|
|
|
729 |
}
|
|
|
730 |
if ( typeof param === "string" ) {
|
|
|
731 |
param = new RegExp( "^(?:" + param + ")$" );
|
|
|
732 |
}
|
|
|
733 |
return param.test( value );
|
|
|
734 |
}, "Invalid format." );
|
|
|
735 |
|
|
|
736 |
/**
|
|
|
737 |
* Dutch phone numbers have 10 digits (or 11 and start with +31).
|
|
|
738 |
*/
|
|
|
739 |
$.validator.addMethod( "phoneNL", function( value, element ) {
|
|
|
740 |
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 );
|
|
|
741 |
}, "Please specify a valid phone number." );
|
|
|
742 |
|
|
|
743 |
/* For UK phone functions, do the following server side processing:
|
|
|
744 |
* Compare original input with this RegEx pattern:
|
|
|
745 |
* ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
|
|
|
746 |
* Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
|
|
|
747 |
* Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
|
|
|
748 |
* A number of very detailed GB telephone number RegEx patterns can also be found at:
|
|
|
749 |
* http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
|
|
|
750 |
*/
|
|
|
751 |
$.validator.addMethod( "phoneUK", function( phone_number, element ) {
|
|
|
752 |
phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );
|
|
|
753 |
return this.optional( element ) || phone_number.length > 9 &&
|
|
|
754 |
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})$/ );
|
|
|
755 |
}, "Please specify a valid phone number" );
|
|
|
756 |
|
|
|
757 |
/**
|
|
|
758 |
* Matches US phone number format
|
|
|
759 |
*
|
|
|
760 |
* where the area code may not start with 1 and the prefix may not start with 1
|
|
|
761 |
* allows '-' or ' ' as a separator and allows parens around area code
|
|
|
762 |
* some people may want to put a '1' in front of their number
|
|
|
763 |
*
|
|
|
764 |
* 1(212)-999-2345 or
|
|
|
765 |
* 212 999 2344 or
|
|
|
766 |
* 212-999-0983
|
|
|
767 |
*
|
|
|
768 |
* but not
|
|
|
769 |
* 111-123-5434
|
|
|
770 |
* and not
|
|
|
771 |
* 212 123 4567
|
|
|
772 |
*/
|
|
|
773 |
$.validator.addMethod( "phoneUS", function( phone_number, element ) {
|
|
|
774 |
phone_number = phone_number.replace( /\s+/g, "" );
|
|
|
775 |
return this.optional( element ) || phone_number.length > 9 &&
|
|
|
776 |
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}$/ );
|
|
|
777 |
}, "Please specify a valid phone number" );
|
|
|
778 |
|
|
|
779 |
/* For UK phone functions, do the following server side processing:
|
|
|
780 |
* Compare original input with this RegEx pattern:
|
|
|
781 |
* ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
|
|
|
782 |
* Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
|
|
|
783 |
* Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
|
|
|
784 |
* A number of very detailed GB telephone number RegEx patterns can also be found at:
|
|
|
785 |
* http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
|
|
|
786 |
*/
|
|
|
787 |
|
|
|
788 |
// Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers
|
|
|
789 |
$.validator.addMethod( "phonesUK", function( phone_number, element ) {
|
|
|
790 |
phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );
|
|
|
791 |
return this.optional( element ) || phone_number.length > 9 &&
|
|
|
792 |
phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/ );
|
|
|
793 |
}, "Please specify a valid uk phone number" );
|
|
|
794 |
|
|
|
795 |
/**
|
|
|
796 |
* Matches a valid Canadian Postal Code
|
|
|
797 |
*
|
|
|
798 |
* @example jQuery.validator.methods.postalCodeCA( "H0H 0H0", element )
|
|
|
799 |
* @result true
|
|
|
800 |
*
|
|
|
801 |
* @example jQuery.validator.methods.postalCodeCA( "H0H0H0", element )
|
|
|
802 |
* @result false
|
|
|
803 |
*
|
|
|
804 |
* @name jQuery.validator.methods.postalCodeCA
|
|
|
805 |
* @type Boolean
|
|
|
806 |
* @cat Plugins/Validate/Methods
|
|
|
807 |
*/
|
|
|
808 |
$.validator.addMethod( "postalCodeCA", function( value, element ) {
|
|
|
809 |
return this.optional( element ) || /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] *\d[ABCEGHJKLMNPRSTVWXYZ]\d$/i.test( value );
|
|
|
810 |
}, "Please specify a valid postal code" );
|
|
|
811 |
|
|
|
812 |
/*
|
|
|
813 |
* Valida CEPs do brasileiros:
|
|
|
814 |
*
|
|
|
815 |
* Formatos aceitos:
|
|
|
816 |
* 99999-999
|
|
|
817 |
* 99.999-999
|
|
|
818 |
* 99999999
|
|
|
819 |
*/
|
|
|
820 |
$.validator.addMethod( "postalcodeBR", function( cep_value, element ) {
|
|
|
821 |
return this.optional( element ) || /^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test( cep_value );
|
|
|
822 |
}, "Informe um CEP válido." );
|
|
|
823 |
|
|
|
824 |
/* Matches Italian postcode (CAP) */
|
|
|
825 |
$.validator.addMethod( "postalcodeIT", function( value, element ) {
|
|
|
826 |
return this.optional( element ) || /^\d{5}$/.test( value );
|
|
|
827 |
}, "Please specify a valid postal code" );
|
|
|
828 |
|
|
|
829 |
$.validator.addMethod( "postalcodeNL", function( value, element ) {
|
|
|
830 |
return this.optional( element ) || /^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/.test( value );
|
|
|
831 |
}, "Please specify a valid postal code" );
|
|
|
832 |
|
|
|
833 |
// Matches UK postcode. Does not match to UK Channel Islands that have their own postcodes (non standard UK)
|
|
|
834 |
$.validator.addMethod( "postcodeUK", function( value, element ) {
|
|
|
835 |
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 );
|
|
|
836 |
}, "Please specify a valid UK postcode" );
|
|
|
837 |
|
|
|
838 |
/*
|
|
|
839 |
* Lets you say "at least X inputs that match selector Y must be filled."
|
|
|
840 |
*
|
|
|
841 |
* The end result is that neither of these inputs:
|
|
|
842 |
*
|
|
|
843 |
* <input class="productinfo" name="partnumber">
|
|
|
844 |
* <input class="productinfo" name="description">
|
|
|
845 |
*
|
|
|
846 |
* ...will validate unless at least one of them is filled.
|
|
|
847 |
*
|
|
|
848 |
* partnumber: {require_from_group: [1,".productinfo"]},
|
|
|
849 |
* description: {require_from_group: [1,".productinfo"]}
|
|
|
850 |
*
|
|
|
851 |
* options[0]: number of fields that must be filled in the group
|
|
|
852 |
* options[1]: CSS selector that defines the group of conditionally required fields
|
|
|
853 |
*/
|
|
|
854 |
$.validator.addMethod( "require_from_group", function( value, element, options ) {
|
|
|
855 |
var $fields = $( options[ 1 ], element.form ),
|
|
|
856 |
$fieldsFirst = $fields.eq( 0 ),
|
|
|
857 |
validator = $fieldsFirst.data( "valid_req_grp" ) ? $fieldsFirst.data( "valid_req_grp" ) : $.extend( {}, this ),
|
|
|
858 |
isValid = $fields.filter( function() {
|
|
|
859 |
return validator.elementValue( this );
|
|
|
860 |
} ).length >= options[ 0 ];
|
|
|
861 |
|
|
|
862 |
// Store the cloned validator for future validation
|
|
|
863 |
$fieldsFirst.data( "valid_req_grp", validator );
|
|
|
864 |
|
|
|
865 |
// If element isn't being validated, run each require_from_group field's validation rules
|
|
|
866 |
if ( !$( element ).data( "being_validated" ) ) {
|
|
|
867 |
$fields.data( "being_validated", true );
|
|
|
868 |
$fields.each( function() {
|
|
|
869 |
validator.element( this );
|
|
|
870 |
} );
|
|
|
871 |
$fields.data( "being_validated", false );
|
|
|
872 |
}
|
|
|
873 |
return isValid;
|
|
|
874 |
}, $.validator.format( "Please fill at least {0} of these fields." ) );
|
|
|
875 |
|
|
|
876 |
/*
|
|
|
877 |
* Lets you say "either at least X inputs that match selector Y must be filled,
|
|
|
878 |
* OR they must all be skipped (left blank)."
|
|
|
879 |
*
|
|
|
880 |
* The end result, is that none of these inputs:
|
|
|
881 |
*
|
|
|
882 |
* <input class="productinfo" name="partnumber">
|
|
|
883 |
* <input class="productinfo" name="description">
|
|
|
884 |
* <input class="productinfo" name="color">
|
|
|
885 |
*
|
|
|
886 |
* ...will validate unless either at least two of them are filled,
|
|
|
887 |
* OR none of them are.
|
|
|
888 |
*
|
|
|
889 |
* partnumber: {skip_or_fill_minimum: [2,".productinfo"]},
|
|
|
890 |
* description: {skip_or_fill_minimum: [2,".productinfo"]},
|
|
|
891 |
* color: {skip_or_fill_minimum: [2,".productinfo"]}
|
|
|
892 |
*
|
|
|
893 |
* options[0]: number of fields that must be filled in the group
|
|
|
894 |
* options[1]: CSS selector that defines the group of conditionally required fields
|
|
|
895 |
*
|
|
|
896 |
*/
|
|
|
897 |
$.validator.addMethod( "skip_or_fill_minimum", function( value, element, options ) {
|
|
|
898 |
var $fields = $( options[ 1 ], element.form ),
|
|
|
899 |
$fieldsFirst = $fields.eq( 0 ),
|
|
|
900 |
validator = $fieldsFirst.data( "valid_skip" ) ? $fieldsFirst.data( "valid_skip" ) : $.extend( {}, this ),
|
|
|
901 |
numberFilled = $fields.filter( function() {
|
|
|
902 |
return validator.elementValue( this );
|
|
|
903 |
} ).length,
|
|
|
904 |
isValid = numberFilled === 0 || numberFilled >= options[ 0 ];
|
|
|
905 |
|
|
|
906 |
// Store the cloned validator for future validation
|
|
|
907 |
$fieldsFirst.data( "valid_skip", validator );
|
|
|
908 |
|
|
|
909 |
// If element isn't being validated, run each skip_or_fill_minimum field's validation rules
|
|
|
910 |
if ( !$( element ).data( "being_validated" ) ) {
|
|
|
911 |
$fields.data( "being_validated", true );
|
|
|
912 |
$fields.each( function() {
|
|
|
913 |
validator.element( this );
|
|
|
914 |
} );
|
|
|
915 |
$fields.data( "being_validated", false );
|
|
|
916 |
}
|
|
|
917 |
return isValid;
|
|
|
918 |
}, $.validator.format( "Please either skip these fields or fill at least {0} of them." ) );
|
|
|
919 |
|
|
|
920 |
/* Validates US States and/or Territories by @jdforsythe
|
|
|
921 |
* Can be case insensitive or require capitalization - default is case insensitive
|
|
|
922 |
* Can include US Territories or not - default does not
|
|
|
923 |
* Can include US Military postal abbreviations (AA, AE, AP) - default does not
|
|
|
924 |
*
|
|
|
925 |
* Note: "States" always includes DC (District of Colombia)
|
|
|
926 |
*
|
|
|
927 |
* Usage examples:
|
|
|
928 |
*
|
|
|
929 |
* This is the default - case insensitive, no territories, no military zones
|
|
|
930 |
* stateInput: {
|
|
|
931 |
* caseSensitive: false,
|
|
|
932 |
* includeTerritories: false,
|
|
|
933 |
* includeMilitary: false
|
|
|
934 |
* }
|
|
|
935 |
*
|
|
|
936 |
* Only allow capital letters, no territories, no military zones
|
|
|
937 |
* stateInput: {
|
|
|
938 |
* caseSensitive: false
|
|
|
939 |
* }
|
|
|
940 |
*
|
|
|
941 |
* Case insensitive, include territories but not military zones
|
|
|
942 |
* stateInput: {
|
|
|
943 |
* includeTerritories: true
|
|
|
944 |
* }
|
|
|
945 |
*
|
|
|
946 |
* Only allow capital letters, include territories and military zones
|
|
|
947 |
* stateInput: {
|
|
|
948 |
* caseSensitive: true,
|
|
|
949 |
* includeTerritories: true,
|
|
|
950 |
* includeMilitary: true
|
|
|
951 |
* }
|
|
|
952 |
*
|
|
|
953 |
*/
|
|
|
954 |
$.validator.addMethod( "stateUS", function( value, element, options ) {
|
|
|
955 |
var isDefault = typeof options === "undefined",
|
|
|
956 |
caseSensitive = ( isDefault || typeof options.caseSensitive === "undefined" ) ? false : options.caseSensitive,
|
|
|
957 |
includeTerritories = ( isDefault || typeof options.includeTerritories === "undefined" ) ? false : options.includeTerritories,
|
|
|
958 |
includeMilitary = ( isDefault || typeof options.includeMilitary === "undefined" ) ? false : options.includeMilitary,
|
|
|
959 |
regex;
|
|
|
960 |
|
|
|
961 |
if ( !includeTerritories && !includeMilitary ) {
|
|
|
962 |
regex = "^(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$";
|
|
|
963 |
} else if ( includeTerritories && includeMilitary ) {
|
|
|
964 |
regex = "^(A[AEKLPRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$";
|
|
|
965 |
} else if ( includeTerritories ) {
|
|
|
966 |
regex = "^(A[KLRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$";
|
|
|
967 |
} else {
|
|
|
968 |
regex = "^(A[AEKLPRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$";
|
|
|
969 |
}
|
|
|
970 |
|
|
|
971 |
regex = caseSensitive ? new RegExp( regex ) : new RegExp( regex, "i" );
|
|
|
972 |
return this.optional( element ) || regex.test( value );
|
|
|
973 |
}, "Please specify a valid state" );
|
|
|
974 |
|
|
|
975 |
// TODO check if value starts with <, otherwise don't try stripping anything
|
|
|
976 |
$.validator.addMethod( "strippedminlength", function( value, element, param ) {
|
|
|
977 |
return $( value ).text().length >= param;
|
|
|
978 |
}, $.validator.format( "Please enter at least {0} characters" ) );
|
|
|
979 |
|
|
|
980 |
$.validator.addMethod( "time", function( value, element ) {
|
|
|
981 |
return this.optional( element ) || /^([01]\d|2[0-3]|[0-9])(:[0-5]\d){1,2}$/.test( value );
|
|
|
982 |
}, "Please enter a valid time, between 00:00 and 23:59" );
|
|
|
983 |
|
|
|
984 |
$.validator.addMethod( "time12h", function( value, element ) {
|
|
|
985 |
return this.optional( element ) || /^((0?[1-9]|1[012])(:[0-5]\d){1,2}(\ ?[AP]M))$/i.test( value );
|
|
|
986 |
}, "Please enter a valid time in 12-hour am/pm format" );
|
|
|
987 |
|
|
|
988 |
// Same as url, but TLD is optional
|
|
|
989 |
$.validator.addMethod( "url2", function( value, element ) {
|
|
|
990 |
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 );
|
|
|
991 |
}, $.validator.messages.url );
|
|
|
992 |
|
|
|
993 |
/**
|
|
|
994 |
* Return true, if the value is a valid vehicle identification number (VIN).
|
|
|
995 |
*
|
|
|
996 |
* Works with all kind of text inputs.
|
|
|
997 |
*
|
|
|
998 |
* @example <input type="text" size="20" name="VehicleID" class="{required:true,vinUS:true}" />
|
|
|
999 |
* @desc Declares a required input element whose value must be a valid vehicle identification number.
|
|
|
1000 |
*
|
|
|
1001 |
* @name $.validator.methods.vinUS
|
|
|
1002 |
* @type Boolean
|
|
|
1003 |
* @cat Plugins/Validate/Methods
|
|
|
1004 |
*/
|
|
|
1005 |
$.validator.addMethod( "vinUS", function( v ) {
|
|
|
1006 |
if ( v.length !== 17 ) {
|
|
|
1007 |
return false;
|
|
|
1008 |
}
|
|
|
1009 |
|
|
|
1010 |
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" ],
|
|
|
1011 |
VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ],
|
|
|
1012 |
FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ],
|
|
|
1013 |
rs = 0,
|
|
|
1014 |
i, n, d, f, cd, cdv;
|
|
|
1015 |
|
|
|
1016 |
for ( i = 0; i < 17; i++ ) {
|
|
|
1017 |
f = FL[ i ];
|
|
|
1018 |
d = v.slice( i, i + 1 );
|
|
|
1019 |
if ( i === 8 ) {
|
|
|
1020 |
cdv = d;
|
|
|
1021 |
}
|
|
|
1022 |
if ( !isNaN( d ) ) {
|
|
|
1023 |
d *= f;
|
|
|
1024 |
} else {
|
|
|
1025 |
for ( n = 0; n < LL.length; n++ ) {
|
|
|
1026 |
if ( d.toUpperCase() === LL[ n ] ) {
|
|
|
1027 |
d = VL[ n ];
|
|
|
1028 |
d *= f;
|
|
|
1029 |
if ( isNaN( cdv ) && n === 8 ) {
|
|
|
1030 |
cdv = LL[ n ];
|
|
|
1031 |
}
|
|
|
1032 |
break;
|
|
|
1033 |
}
|
|
|
1034 |
}
|
|
|
1035 |
}
|
|
|
1036 |
rs += d;
|
|
|
1037 |
}
|
|
|
1038 |
cd = rs % 11;
|
|
|
1039 |
if ( cd === 10 ) {
|
|
|
1040 |
cd = "X";
|
|
|
1041 |
}
|
|
|
1042 |
if ( cd === cdv ) {
|
|
|
1043 |
return true;
|
|
|
1044 |
}
|
|
|
1045 |
return false;
|
|
|
1046 |
}, "The specified vehicle identification number (VIN) is invalid." );
|
|
|
1047 |
|
|
|
1048 |
$.validator.addMethod( "zipcodeUS", function( value, element ) {
|
|
|
1049 |
return this.optional( element ) || /^\d{5}(-\d{4})?$/.test( value );
|
|
|
1050 |
}, "The specified US ZIP Code is invalid" );
|
|
|
1051 |
|
|
|
1052 |
$.validator.addMethod( "ziprange", function( value, element ) {
|
|
|
1053 |
return this.optional( element ) || /^90[2-5]\d\{2\}-\d{4}$/.test( value );
|
|
|
1054 |
}, "Your ZIP-code must be in the range 902xx-xxxx to 905xx-xxxx" );
|
|
|
1055 |
|
|
|
1056 |
}));
|