1/** 2 * jQuery Validation Plugin 1.9.0 3 * 4 * http://bassistance.de/jquery-plugins/jquery-plugin-validation/ 5 * http://docs.jquery.com/Plugins/Validation 6 * 7 * Copyright (c) 2006 - 2011 Jörn Zaefferer 8 * 9 * Dual licensed under the MIT and GPL licenses: 10 * http://www.opensource.org/licenses/mit-license.php 11 * http://www.gnu.org/licenses/gpl.html 12 */ 13 14(function() { 15 16 function stripHtml(value) { 17 // remove html tags and space chars 18 return value.replace(/<.[^<>]*?>/g, ' ').replace(/ | /gi, ' ') 19 // remove numbers and punctuation 20 .replace(/[0-9.(),;:!?%#$'"_+=\/-]*/g,''); 21 } 22 jQuery.validator.addMethod("maxWords", function(value, element, params) { 23 return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length < params; 24 }, jQuery.validator.format("Please enter {0} words or less.")); 25 26 jQuery.validator.addMethod("minWords", function(value, element, params) { 27 return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length >= params; 28 }, jQuery.validator.format("Please enter at least {0} words.")); 29 30 jQuery.validator.addMethod("rangeWords", function(value, element, params) { 31 return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length >= params[0] && value.match(/bw+b/g).length < params[1]; 32 }, jQuery.validator.format("Please enter between {0} and {1} words.")); 33 34})(); 35 36jQuery.validator.addMethod("letterswithbasicpunc", function(value, element) { 37 return this.optional(element) || /^[a-z-.,()'\"\s]+$/i.test(value); 38}, "Letters or punctuation only please"); 39 40jQuery.validator.addMethod("alphanumeric", function(value, element) { 41 return this.optional(element) || /^\w+$/i.test(value); 42}, "Letters, numbers, spaces or underscores only please"); 43 44jQuery.validator.addMethod("lettersonly", function(value, element) { 45 return this.optional(element) || /^[a-z]+$/i.test(value); 46}, "Letters only please"); 47 48jQuery.validator.addMethod("nowhitespace", function(value, element) { 49 return this.optional(element) || /^\S+$/i.test(value); 50}, "No white space please"); 51 52jQuery.validator.addMethod("ziprange", function(value, element) { 53 return this.optional(element) || /^90[2-5]\d\{2}-\d{4}$/.test(value); 54}, "Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx"); 55 56jQuery.validator.addMethod("integer", function(value, element) { 57 return this.optional(element) || /^-?\d+$/.test(value); 58}, "A positive or negative non-decimal number please"); 59 60/** 61* Return true, if the value is a valid vehicle identification number (VIN). 62* 63* Works with all kind of text inputs. 64* 65* @example <input type="text" size="20" name="VehicleID" class="{required:true,vinUS:true}" /> 66* @desc Declares a required input element whose value must be a valid vehicle identification number. 67* 68* @name jQuery.validator.methods.vinUS 69* @type Boolean 70* @cat Plugins/Validate/Methods 71*/ 72jQuery.validator.addMethod( 73 "vinUS", 74 function(v){ 75 if (v.length != 17) 76 return false; 77 var i, n, d, f, cd, cdv; 78 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"]; 79 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]; 80 var FL = [8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2]; 81 var rs = 0; 82 for(i = 0; i < 17; i++){ 83 f = FL[i]; 84 d = v.slice(i,i+1); 85 if(i == 8){ 86 cdv = d; 87 } 88 if(!isNaN(d)){ 89 d *= f; 90 } 91 else{ 92 for(n = 0; n < LL.length; n++){ 93 if(d.toUpperCase() === LL[n]){ 94 d = VL[n]; 95 d *= f; 96 if(isNaN(cdv) && n == 8){ 97 cdv = LL[n]; 98 } 99 break; 100 } 101 } 102 } 103 rs += d; 104 } 105 cd = rs % 11; 106 if(cd == 10){cd = "X";} 107 if(cd == cdv){return true;} 108 return false; 109 },
110 "The specified vehicle identification number (VIN) is invalid." 111); 112 113/** 114 * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy. 115 * 116 * @example jQuery.validator.methods.date("01/01/1900") 117 * @result true 118 * 119 * @example jQuery.validator.methods.date("01/13/1990") 120 * @result false 121 * 122 * @example jQuery.validator.methods.date("01.01.1900") 123 * @result false 124 * 125 * @example <input name="pippo" class="{dateITA:true}" /> 126 * @desc Declares an optional input element whose value must be a valid date. 127 * 128 * @name jQuery.validator.methods.dateITA 129 * @type Boolean 130 * @cat Plugins/Validate/Methods 131 */ 132jQuery.validator.addMethod( 133 "dateITA", 134 function(value, element) { 135 var check = false; 136 var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/; 137 if( re.test(value)){ 138 var adata = value.split('/'); 139 var gg = parseInt(adata[0],10); 140 var mm = parseInt(adata[1],10); 141 var aaaa = parseInt(adata[2],10); 142 var xdata = new Date(aaaa,mm-1,gg); 143 if ( ( xdata.getFullYear() == aaaa ) && ( xdata.getMonth () == mm - 1 ) && ( xdata.getDate() == gg ) ) 144 check = true; 145 else 146 check = false; 147 } else 148 check = false; 149 return this.optional(element) || check; 150 }, 151 "Please enter a correct date" 152); 153 154jQuery.validator.addMethod("dateNL", function(value, element) { 155 return this.optional(element) || /^\d\d?[\.\/-]\d\d?[\.\/-]\d\d\d?\d?$/.test(value); 156 }, "Vul hier een geldige datum in." 157); 158 159jQuery.validator.addMethod("time", function(value, element) { 160 return this.optional(element) || /^([01]\d|2[0-3])(:[0-5]\d){0,2}$/.test(value); 161}, "Please enter a valid time, between 00:00 and 23:59"); 162jQuery.validator.addMethod("time12h", function(value, element) { 163 return this.optional(element) || /^((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))$/i.test(value); 164}, "Please enter a valid time, between 00:00 am and 12:00 pm"); 165 166/** 167 * matches US phone number format 168 * 169 * where the area code may not start with 1 and the prefix may not start with 1 170 * allows '-' or ' ' as a separator and allows parens around area code 171 * some people may want to put a '1' in front of their number 172 * 173 * 1(212)-999-2345 174 * or 175 * 212 999 2344 176 * or 177 * 212-999-0983 178 * 179 * but not 180 * 111-123-5434 181 * and not 182 * 212 123 4567 183 */ 184jQuery.validator.addMethod("phoneUS", function(phone_number, element) { 185 phone_number = phone_number.replace(/\s+/g, ""); 186 return this.optional(element) || phone_number.length > 9 && 187 phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/); 188}, "Please specify a valid phone number"); 189 190jQuery.validator.addMethod('phoneUK', function(phone_number, element) { 191return this.optional(element) || phone_number.length > 9 && 192phone_number.match(/^(\(?(0|\+44)[1-9]{1}\d{1,4}?\)?\s?\d{3,4}\s?\d{3,4})$/); 193}, 'Please specify a valid phone number'); 194 195jQuery.validator.addMethod('mobileUK', function(phone_number, element) { 196return this.optional(element) || phone_number.length > 9 && 197phone_number.match(/^((0|\+44)7(5|6|7|8|9){1}\d{2}\s?\d{6})$/); 198}, 'Please specify a valid mobile number'); 199 200// TODO check if value starts with <, otherwise don't try stripping anything 201jQuery.validator.addMethod("strippedminlength", function(value, element, param) { 202 return jQuery(value).text().length >= param; 203}, jQuery.validator.format("Please enter at least {0} characters")); 204 205// same as email, but TLD is optional 206jQuery.validator.addMethod("email2", function(value, element, param) { 207 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); 208}, jQuery.validator.messages.email); 209 210// same as url, but TLD is optional 211jQuery.validator.addMethod("url2", function(value, element, param) { 212 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); 213}, jQuery.validator.messages.url); 214 215// NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator 216// Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0 217// Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings) 218jQuery.validator.addMethod("creditcardtypes", function(value, element, param) { 219 220 if (/[^0-9-]+/.test(value)) 221 return false;
222 223 value = value.replace(/\D/g, ""); 224 225 var validTypes = 0x0000; 226 227 if (param.mastercard) 228 validTypes |= 0x0001; 229 if (param.visa) 230 validTypes |= 0x0002; 231 if (param.amex) 232 validTypes |= 0x0004; 233 if (param.dinersclub) 234 validTypes |= 0x0008; 235 if (param.enroute) 236 validTypes |= 0x0010; 237 if (param.discover) 238 validTypes |= 0x0020; 239 if (param.jcb) 240 validTypes |= 0x0040; 241 if (param.unknown) 242 validTypes |= 0x0080; 243 if (param.all) 244 validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080; 245 246 if (validTypes & 0x0001 && /^(51|52|53|54|55)/.test(value)) { //mastercard 247 return value.length == 16; 248 } 249 if (validTypes & 0x0002 && /^(4)/.test(value)) { //visa 250 return value.length == 16; 251 } 252 if (validTypes & 0x0004 && /^(34|37)/.test(value)) { //amex 253 return value.length == 15; 254 } 255 if (validTypes & 0x0008 && /^(300|301|302|303|304|305|36|38)/.test(value)) { //dinersclub 256 return value.length == 14; 257 } 258 if (validTypes & 0x0010 && /^(2014|2149)/.test(value)) { //enroute 259 return value.length == 15; 260 } 261 if (validTypes & 0x0020 && /^(6011)/.test(value)) { //discover 262 return value.length == 16; 263 } 264 if (validTypes & 0x0040 && /^(3)/.test(value)) { //jcb 265 return value.length == 16; 266 } 267 if (validTypes & 0x0040 && /^(2131|1800)/.test(value)) { //jcb 268 return value.length == 15; 269 } 270 if (validTypes & 0x0080) { //unknown 271 return true; 272 } 273 return false; 274}, "Please enter a valid credit card number."); 275 276jQuery.validator.addMethod("ipv4", function(value, element, param) { 277 return this.optional(element) || /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i.test(value); 278}, "Please enter a valid IP v4 address."); 279 280jQuery.validator.addMethod("ipv6", function(value, element, param) { 281 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); 282}, "Please enter a valid IP v6 address."); 283 284/** 285 * Return true if the field value matches the given format RegExp 286 * 287 * @example jQuery.validator.methods.pattern("AR1004",element,/^AR\d{4}$/) 288 * @result true 289 * 290 * @example jQuery.validator.methods.pattern("BR1004",element,/^AR\d{4}$/) 291 * @result false 292 * 293 * @name jQuery.validator.methods.pattern 294 * @type Boolean 295 * @cat Plugins/Validate/Methods 296 */ 297jQuery.validator.addMethod("pattern", function(value, element, param) { 298 return this.optional(element) || param.test(value); 299}, "Invalid format."); 300
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.