1/*! jQuery Validation Plugin - v1.10.0 - 9/7/2012 2* https://github.com/jzaefferer/jquery-validation 3* Copyright (c) 2012 Jörn Zaefferer; Licensed MIT, GPL */ 4 5/*! 6 * jQuery Validation Plugin 1.10.0 7 * 8 * http://bassistance.de/jquery-plugins/jquery-plugin-validation/ 9 * http://docs.jquery.com/Plugins/Validation 10 * 11 * Copyright (c) 2006 - 2011 Jörn Zaefferer 12 * 13 * Dual licensed under the MIT and GPL licenses: 14 * http://www.opensource.org/licenses/mit-license.php 15 * http://www.gnu.org/licenses/gpl.html 16 */ 17 18(function() { 19 20 function stripHtml(value) { 21 // remove html tags and space chars 22 return value.replace(/<.[^<>]*?>/g, ' ').replace(/ | /gi, ' ') 23 // remove punctuation 24 .replace(/[.(),;:!?%#$'"_+=\/-]*/g,''); 25 } 26 jQuery.validator.addMethod("maxWords", function(value, element, params) { 27 return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length <= params; 28 }, jQuery.validator.format("Please enter {0} words or less.")); 29 30 jQuery.validator.addMethod("minWords", function(value, element, params) { 31 return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length >= params; 32 }, jQuery.validator.format("Please enter at least {0} words.")); 33 34 jQuery.validator.addMethod("rangeWords", function(value, element, params) { 35 var valueStripped = stripHtml(value); 36 var regex = /\b\w+\b/g; 37 return this.optional(element) || valueStripped.match(regex).length >= params[0] && valueStripped.match(regex).length <= params[1]; 38 }, jQuery.validator.format("Please enter between {0} and {1} words.")); 39 40})(); 41 42jQuery.validator.addMethod("letterswithbasicpunc", function(value, element) { 43 return this.optional(element) || /^[a-z\-.,()'\"\s]+$/i.test(value); 44}, "Letters or punctuation only please"); 45 46jQuery.validator.addMethod("alphanumeric", function(value, element) { 47 return this.optional(element) || /^\w+$/i.test(value); 48}, "Letters, numbers, and underscores only please"); 49 50jQuery.validator.addMethod("lettersonly", function(value, element) { 51 return this.optional(element) || /^[a-z]+$/i.test(value); 52}, "Letters only please"); 53 54jQuery.validator.addMethod("nowhitespace", function(value, element) { 55 return this.optional(element) || /^\S+$/i.test(value); 56}, "No white space please"); 57 58jQuery.validator.addMethod("ziprange", function(value, element) { 59 return this.optional(element) || /^90[2-5]\d\{2\}-\d{4}$/.test(value); 60}, "Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx"); 61 62jQuery.validator.addMethod("zipcodeUS", function(value, element) { 63 return this.optional(element) || /\d{5}-\d{4}$|^\d{5}$/.test(value) 64}, "The specified US ZIP Code is invalid"); 65 66jQuery.validator.addMethod("integer", function(value, element) { 67 return this.optional(element) || /^-?\d+$/.test(value); 68}, "A positive or negative non-decimal number please"); 69 70/** 71 * Return true, if the value is a valid vehicle identification number (VIN). 72 * 73 * Works with all kind of text inputs. 74 * 75 * @example <input type="text" size="20" name="VehicleID" class="{required:true,vinUS:true}" /> 76 * @desc Declares a required input element whose value must be a valid vehicle identification number. 77 * 78 * @name jQuery.validator.methods.vinUS 79 * @type Boolean 80 * @cat Plugins/Validate/Methods 81 */ 82jQuery.validator.addMethod("vinUS", function(v) { 83 if (v.length != 17) { 84 return false; 85 } 86 var i, n, d, f, cd, cdv; 87 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"]; 88 var VL = [1,2,3,4,5,6,7,8,1,2,3,4,5,7,9,2,3,4,5,6,7,8,9]; 89 var FL = [8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2]; 90 var rs = 0; 91 for(i = 0; i < 17; i++){ 92 f = FL[i]; 93 d = v.slice(i,i+1); 94 if (i == 8) { 95 cdv = d; 96 } 97 if (!isNaN(d)) { 98 d *= f; 99 } else { 100 for (n = 0; n < LL.length; n++) { 101 if (d.toUpperCase() === LL[n]) { 102 d = VL[n]; 103 d *= f; 104 if (isNaN(cdv) && n == 8) { 105 cdv = LL[n]; 106 } 107 break; 108 } 109 } 110 } 111 rs += d; 112 } 113 cd = rs % 11; 114 if (cd == 10) { 115 cd = "X"; 116 } 117 if (cd == cdv) { 118 return true; 119 } 120 return false; 121}
121, "The specified vehicle identification number (VIN) is invalid."); 122 123/** 124 * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy. 125 * 126 * @example jQuery.validator.methods.date("01/01/1900") 127 * @result true 128 * 129 * @example jQuery.validator.methods.date("01/13/1990") 130 * @result false 131 * 132 * @example jQuery.validator.methods.date("01.01.1900") 133 * @result false 134 * 135 * @example <input name="pippo" class="{dateITA:true}" /> 136 * @desc Declares an optional input element whose value must be a valid date. 137 * 138 * @name jQuery.validator.methods.dateITA 139 * @type Boolean 140 * @cat Plugins/Validate/Methods 141 */ 142jQuery.validator.addMethod("dateITA", function(value, element) { 143 var check = false; 144 var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/; 145 if( re.test(value)){ 146 var adata = value.split('/'); 147 var gg = parseInt(adata[0],10); 148 var mm = parseInt(adata[1],10); 149 var aaaa = parseInt(adata[2],10); 150 var xdata = new Date(aaaa,mm-1,gg); 151 if ( ( xdata.getFullYear() == aaaa ) && ( xdata.getMonth () == mm - 1 ) && ( xdata.getDate() == gg ) ) 152 check = true; 153 else 154 check = false; 155 } else 156 check = false; 157 return this.optional(element) || check; 158}, "Please enter a correct date"); 159 160jQuery.validator.addMethod("dateNL", function(value, element) { 161 return this.optional(element) || /^\d\d?[\.\/-]\d\d?[\.\/-]\d\d\d?\d?$/.test(value); 162}, "Vul hier een geldige datum in."); 163 164jQuery.validator.addMethod("time", function(value, element) { 165 return this.optional(element) || /^([0-1]\d|2[0-3]):([0-5]\d)$/.test(value); 166}, "Please enter a valid time, between 00:00 and 23:59"); 167jQuery.validator.addMethod("time12h", function(value, element) { 168 return this.optional(element) || /^((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))$/i.test(value); 169}, "Please enter a valid time, between 00:00 am and 12:00 pm"); 170 171/** 172 * matches US phone number format 173 * 174 * where the area code may not start with 1 and the prefix may not start with 1 175 * allows '-' or ' ' as a separator and allows parens around area code 176 * some people may want to put a '1' in front of their number 177 * 178 * 1(212)-999-2345 or 179 * 212 999 2344 or 180 * 212-999-0983 181 * 182 * but not 183 * 111-123-5434 184 * and not 185 * 212 123 4567 186 */ 187jQuery.validator.addMethod("phoneUS", function(phone_number, element) { 188 phone_number = phone_number.replace(/\s+/g, ""); 189 return this.optional(element) || phone_number.length > 9 && 190 phone_number.match(/^(\+?1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/); 191}, "Please specify a valid phone number"); 192 193jQuery.validator.addMethod('phoneUK', function(phone_number, element) { 194 phone_number = phone_number.replace(/\(|\)|\s+|-/g,''); 195 return this.optional(element) || phone_number.length > 9 && 196 phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:(?:\d{5}\)?\s?\d{4,5})|(?:\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3}))|(?:\d{3}\)?\s?\d{3}\s?\d{3,4})|(?:\d{2}\)?\s?\d{4}\s?\d{4}))$/); 197}, 'Please specify a valid phone number'); 198 199jQuery.validator.addMethod('mobileUK', function(phone_number, element) { 200 phone_number = phone_number.replace(/\s+|-/g,''); 201 return this.optional(element) || phone_number.length > 9 && 202 phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[45789]\d{2}|624)\s?\d{3}\s?\d{3})$/); 203}, 'Please specify a valid mobile number'); 204 205//Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers 206jQuery.validator.addMethod('phonesUK', function(phone_number, element) { 207 phone_number = phone_number.replace(/\s+|-/g,''); 208 return this.optional(element) || phone_number.length > 9 && 209 phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[45789]\d{8}|624\d{6})))$/); 210}, 'Please specify a valid uk phone number'); 211// On the above three UK functions, do the following server side processing: 212// Compare with ^((?:00\s?|\+)(44)\s?)?\(?0?(?:\)\s?)?([1-9]\d{1,4}\)?[\d\s]+) 213// Extract $2 and set $prefix to '+44<space>' if $2 is '44' otherwise set $prefix to '0' 214// Extract $3 and remove spaces and parentheses. Phone number is combined $2 and $3. 215// A number of very detailed GB telephone number RegEx patterns can also be found at: 216// http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_UK_Telephone_Numbers 217 218//Matches UK postcode. based on http://snipplr.com/view/3152/postcode-validation/ 219jQuery.validator.addMethod('postcodeUK', function(postcode, element) { 220 postcode = (postcode.toUpperCase()).replace(/\s+/g,''); 221 return this.optional(element) || postcode.match(/^([^QZ][^IJZ]{0,1}\d{1,2})(\d[^CIKMOV]{2})$/) || postcode.match(/^([^QV]\d[ABCDEFGHJKSTUW])(\d[^CIKMOV]{2})$/) || postcode.match(/^([^QV][^IJZ]\d[ABEHMNPRVWXY])(\d[^CIKMOV]{2}
221)$/) || postcode.match(/^(GIR)(0AA)$/) || postcode.match(/^(BFPO)(\d{1,4})$/) || postcode.match(/^(BFPO)(C\/O\d{1,3})$/); 222}, 'Please specify a valid postcode'); 223 224// TODO check if value starts with <, otherwise don't try stripping anything 225jQuery.validator.addMethod("strippedminlength", function(value, element, param) { 226 return jQuery(value).text().length >= param; 227}, jQuery.validator.format("Please enter at least {0} characters")); 228 229// same as email, but TLD is optional 230jQuery.validator.addMethod("email2", function(value, element, param) { 231 return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([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])))\.?$/i.test(value); 232}, jQuery.validator.messages.email); 233 234// same as url, but TLD is optional 235jQuery.validator.addMethod("url2", function(value, element, param) { 236 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); 237}, jQuery.validator.messages.url); 238 239// NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator 240// Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0 241// Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings) 242jQuery.validator.addMethod("creditcardtypes", function(value, element, param) { 243 if (/[^0-9-]+/.test(value)) { 244 return false; 245 } 246 247 value = value.replace(/\D/g, ""); 248 249 var validTypes = 0x0000; 250 251 if (param.mastercard) 252 validTypes |= 0x0001; 253 if (param.visa) 254 validTypes |= 0x0002; 255 if (param.amex) 256 validTypes |= 0x0004; 257 if (param.dinersclub) 258 validTypes |= 0x0008; 259 if (param.enroute) 260 validTypes |= 0x0010; 261 if (param.discover) 262 validTypes |= 0x0020; 263 if (param.jcb) 264 validTypes |= 0x0040; 265 if (param.unknown) 266 validTypes |= 0x0080; 267 if (param.all) 268 validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080; 269 270 if (validTypes & 0x0001 && /^(5[12345])/.test(value)) { //mastercard 271 return value.length == 16; 272 } 273 if (validTypes & 0x0002 && /^(4)/.test(value)) { //visa 274 return value.length == 16; 275 } 276 if (validTypes & 0x0004 && /^(3[47])/.test(value)) { //amex 277 return value.length == 15; 278 } 279 if (validTypes & 0x0008 && /^(3(0[012345]|[68]))/.test(value)) { //dinersclub 280 return value.length == 14; 281 } 282 if (validTypes & 0x0010 && /^(2(014|149))/.test(value)) { //enroute 283 return value.length == 15; 284 } 285 if (validTypes & 0x0020 && /^(6011)/.test(value)) { //discover 286 return value.length == 16; 287 } 288 if (validTypes & 0x0040 && /^(3)/.test(value)) { //jcb 289 return value.length == 16; 290 } 291 if (validTypes & 0x0040 && /^(2131|1800)/.test(value)) { //jcb 292 return value.length == 15; 293 } 294 if (validTypes & 0x0080) { //unknown 295 return true; 296 } 297 return false;
298}, "Please enter a valid credit card number."); 299 300jQuery.validator.addMethod("ipv4", function(value, element, param) { 301 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); 302}, "Please enter a valid IP v4 address."); 303 304jQuery.validator.addMethod("ipv6", function(value, element, param) { 305 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); 306}, "Please enter a valid IP v6 address."); 307 308/** 309* Return true if the field value matches the given format RegExp 310* 311* @example jQuery.validator.methods.pattern("AR1004",element,/^AR\d{4}$/) 312* @result true 313* 314* @example jQuery.validator.methods.pattern("BR1004",element,/^AR\d{4}$/) 315* @result false 316* 317* @name jQuery.validator.methods.pattern 318* @type Boolean 319* @cat Plugins/Validate/Methods 320*/ 321jQuery.validator.addMethod("pattern", function(value, element, param) { 322 if (this.optional(element)) { 323 return true; 324 } 325 if (typeof param === 'string') { 326 param = new RegExp('^(?:' + param + ')$'); 327 } 328 return param.test(value); 329}, "Invalid format."); 330 331 332/* 333 * Lets you say "at least X inputs that match selector Y must be filled." 334 * 335 * The end result is that neither of these inputs: 336 * 337 * <input class="productinfo" name="partnumber"> 338 * <input class="productinfo" name="description"> 339 * 340 * ...will validate unless at least one of them is filled. 341 * 342 * partnumber: {require_from_group: [1,".productinfo"]}, 343 * description: {require_from_group: [1,".productinfo"]} 344 * 345 */ 346jQuery.validator.addMethod("require_from_group", function(value, element, options) { 347 var validator = this; 348 var selector = options[1]; 349 var validOrNot = $(selector, element.form).filter(function() { 350 return validator.elementValue(this); 351 }).length >= options[0]; 352 353 if(!$(element).data('being_validated')) { 354 var fields = $(selector, element.form); 355 fields.data('being_validated', true); 356 fields.valid(); 357 fields.data('being_validated', false); 358 } 359 return validOrNot; 360}, jQuery.format("Please fill at least {0} of these fields.")); 361 362/* 363 * Lets you say "either at least X inputs that match selector Y must be filled, 364 * OR they must all be skipped (left blank)." 365 * 366 * The end result, is that none of these inputs: 367 * 368 * <input class="productinfo" name="partnumber"> 369 * <input class="productinfo" name="description"> 370 * <input class="productinfo" name="color"> 371 * 372 * ...will validate unless either at least two of them are filled, 373 * OR none of them are. 374 * 375 * partnumber: {skip_or_fill_minimum: [2,".productinfo"]}, 376 * description: {skip_or_fill_minimum: [2,".productinfo"]}, 377 * color: {skip_or_fill_minimum: [2,".productinfo"]} 378 * 379 */ 380jQuery.validator.addMethod("skip_or_fill_minimum", function(value, element, options) { 381 var validator = this; 382 383 numberRequired = options[0]; 384 selector = options[1]; 385 var numberFilled = $(selector, element.form).filter(function() { 386 return validator.elementValue(this); 387 }).length; 388 var valid = numberFilled >= numberRequired || numberFilled === 0; 389 390 if(!$(element).data('being_validated')) { 391 var fields = $(selector, element.form); 392 fields.data('being_validated', true); 393 fields.valid(); 394 fields.data('being_validated', false); 395 } 396 return valid; 397}, jQuery.format("Please either skip these fields or fill at least {0} of them.")); 398 399// Accept a value from a file input based on a required mimetype 400jQuery.validator.addMethod("accept", function(value, element, param) { 401 // Split mime on commas incase we have multiple types we can accept 402 var typeParam = typeof param === "string" ? param.replace(/,/g, '|') : "image/*", 403 optionalValue = this.optional(element), 404 i, file; 405 406 // Element is optional 407 if(optionalValue) { 408 return optionalValue; 409 } 410 411 if($(element).attr("type") === "file") { 412 // If we are using a wildcard, make it regex friendly 413 typeParam = typeParam.replace("*", ".*"); 414 415 // Check if the element has a FileList before checking each file 416 if(element.files && element.files.length) { 417 for(i = 0; i < element.files.length; i++) { 418 file = element.files[i]; 419 420 // Grab the mimtype from the loaded file, verify it matches 421 if(!file.type.match(new RegExp( ".?(" + typeParam + ")$", "i"))) { 422 return false;
423 } 424 } 425 } 426 } 427 428 // Either return true because we've validated each file, or because the 429 // browser does not support element.files and the FileList feature 430 return true; 431}, jQuery.format("Please enter a value with a valid mimetype.")); 432 433// Older "accept" file extension method. Old docs: http://docs.jquery.com/Plugins/Validation/Methods/accept 434jQuery.validator.addMethod("extension", function(value, element, param) { 435 param = typeof param === "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif"; 436 return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i")); 437}, jQuery.format("Please enter a value with a valid extension."));
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.