lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 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 | |
| 23 | jQuery.validator.addMethod("maxWords", function (value, element, params) { |
| 24 | return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length < params; |
| 25 | }, jQuery.validator.format("Please enter {0} words or less.")); |
| 26 | |
| 27 | jQuery.validator.addMethod("minWords", function (value, element, params) { |
| 28 | return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length >= params; |
| 29 | }, jQuery.validator.format("Please enter at least {0} words.")); |
| 30 | |
| 31 | jQuery.validator.addMethod("rangeWords", function (value, element, params) { |
| 32 | return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length >= params[0] && value.match(/bw+b/g).length < params[1]; |
| 33 | }, jQuery.validator.format("Please enter between {0} and {1} words.")); |
| 34 | |
| 35 | })(); |
| 36 | |
| 37 | jQuery.validator.addMethod("letterswithbasicpunc", function (value, element) { |
| 38 | return this.optional(element) || /^[a-z-.,()'\"\s]+$/i.test(value); |
| 39 | }, "Letters or punctuation only please"); |
| 40 | |
| 41 | jQuery.validator.addMethod("alphanumeric", function (value, element) { |
| 42 | return this.optional(element) || /^\w+$/i.test(value); |
| 43 | }, "Letters, numbers, spaces or underscores only please"); |
| 44 | |
| 45 | jQuery.validator.addMethod("lettersonly", function (value, element) { |
| 46 | return this.optional(element) || /^[a-z]+$/i.test(value); |
| 47 | }, "Letters only please"); |
| 48 | |
| 49 | jQuery.validator.addMethod("nowhitespace", function (value, element) { |
| 50 | return this.optional(element) || /^\S+$/i.test(value); |
| 51 | }, "No white space please"); |
| 52 | |
| 53 | jQuery.validator.addMethod("ziprange", function (value, element) { |
| 54 | return this.optional(element) || /^90[2-5]\d\{2}-\d{4}$/.test(value); |
| 55 | }, "Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx"); |
| 56 | |
| 57 | jQuery.validator.addMethod("integer", function (value, element) { |
| 58 | return this.optional(element) || /^-?\d+$/.test(value); |
| 59 | }, "A positive or negative non-decimal number please"); |
| 60 | |
| 61 | /** |
| 62 | * Return true, if the value is a valid vehicle identification number (VIN). |
| 63 | * |
| 64 | * Works with all kind of text inputs. |
| 65 | * |
| 66 | * @example <input type="text" size="20" name="VehicleID" class="{required:true,vinUS:true}" /> |
| 67 | * @desc Declares a required input element whose value must be a valid vehicle identification number. |
| 68 | * |
| 69 | * @name jQuery.validator.methods.vinUS |
| 70 | * @type Boolean |
| 71 | * @cat Plugins/Validate/Methods |
| 72 | */ |
| 73 | jQuery.validator.addMethod( |
| 74 | "vinUS", |
| 75 | function (v) { |
| 76 | if (v.length != 17) |
| 77 | return false; |
| 78 | var i, n, d, f, cd, cdv; |
| 79 | 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"]; |
| 80 | 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]; |
| 81 | var FL = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2]; |
| 82 | var rs = 0; |
| 83 | for (i = 0; i < 17; i++) { |
| 84 | f = FL[i]; |
| 85 | d = v.slice(i, i + 1); |
| 86 | if (i == 8) { |
| 87 | cdv = d; |
| 88 | } |
| 89 | if (!isNaN(d)) { |
| 90 | d *= f; |
| 91 | } |
| 92 | else { |
| 93 | for (n = 0; n < LL.length; n++) { |
| 94 | if (d.toUpperCase() === LL[n]) { |
| 95 | d = VL[n]; |
| 96 | d *= f; |
| 97 | if (isNaN(cdv) && n == 8) { |
| 98 | cdv = LL[n]; |
| 99 | } |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | rs += d; |
| 105 | } |
| 106 | cd = rs % 11; |
| 107 | if (cd == 10) { |
| 108 | cd = "X"; |
| 109 | } |
| 110 | if (cd == cdv) { |
| 111 | return true; |
| 112 | } |
| 113 | return false; |
| 114 | }, |
| 115 | "The specified vehicle identification number (VIN) is invalid." |
| 116 | ); |
| 117 | |
| 118 | /** |
| 119 | * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy. |
| 120 | * |
| 121 | * @example jQuery.validator.methods.date("01/01/1900") |
| 122 | * @result true |
| 123 | * |
| 124 | * @example jQuery.validator.methods.date("01/13/1990") |
| 125 | * @result false |
| 126 | * |
| 127 | * @example jQuery.validator.methods.date("01.01.1900") |
| 128 | * @result false |
| 129 | * |
| 130 | * @example <input name="pippo" class="{dateITA:true}" /> |
| 131 | * @desc Declares an optional input element whose value must be a valid date. |
| 132 | * |
| 133 | * @name jQuery.validator.methods.dateITA |
| 134 | * @type Boolean |
| 135 | * @cat Plugins/Validate/Methods |
| 136 | */ |
| 137 | jQuery.validator.addMethod( |
| 138 | "dateITA", |
| 139 | function (value, element) { |
| 140 | var check = false; |
| 141 | var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/; |
| 142 | if (re.test(value)) { |
| 143 | var adata = value.split('/'); |
| 144 | var gg = parseInt(adata[0], 10); |
| 145 | var mm = parseInt(adata[1], 10); |
| 146 | var aaaa = parseInt(adata[2], 10); |
| 147 | var xdata = new Date(aaaa, mm - 1, gg); |
| 148 | if (( xdata.getFullYear() == aaaa ) && ( xdata.getMonth() == mm - 1 ) && ( xdata.getDate() == gg )) |
| 149 | check = true; |
| 150 | else |
| 151 | check = false; |
| 152 | } else |
| 153 | check = false; |
| 154 | return this.optional(element) || check; |
| 155 | }, |
| 156 | "Please enter a correct date" |
| 157 | ); |
| 158 | |
| 159 | jQuery.validator.addMethod("dateNL", function (value, element) { |
| 160 | return this.optional(element) || /^\d\d?[\.\/-]\d\d?[\.\/-]\d\d\d?\d?$/.test(value); |
| 161 | }, "Vul hier een geldige datum in." |
| 162 | ); |
| 163 | |
| 164 | jQuery.validator.addMethod("time", function (value, element) { |
| 165 | return this.optional(element) || /^([01]\d|2[0-3])(:[0-5]\d){0,2}$/.test(value); |
| 166 | }, "Please enter a valid time, between 00:00 and 23:59"); |
| 167 | jQuery.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 |
| 179 | * or |
| 180 | * 212 999 2344 |
| 181 | * or |
| 182 | * 212-999-0983 |
| 183 | * |
| 184 | * but not |
| 185 | * 111-123-5434 |
| 186 | * and not |
| 187 | * 212 123 4567 |
| 188 | */ |
| 189 | jQuery.validator.addMethod("phoneUS", function (phone_number, element) { |
| 190 | phone_number = phone_number.replace(/\s+/g, ""); |
| 191 | return this.optional(element) || phone_number.length > 9 && |
| 192 | phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/); |
| 193 | }, "Please specify a valid phone number"); |
| 194 | |
| 195 | jQuery.validator.addMethod('phoneUK', function (phone_number, element) { |
| 196 | return this.optional(element) || phone_number.length > 9 && |
| 197 | phone_number.match(/^(\(?(0|\+44)[1-9]{1}\d{1,4}?\)?\s?\d{3,4}\s?\d{3,4})$/); |
| 198 | }, 'Please specify a valid phone number'); |
| 199 | |
| 200 | jQuery.validator.addMethod('mobileUK', function (phone_number, element) { |
| 201 | return this.optional(element) || phone_number.length > 9 && |
| 202 | phone_number.match(/^((0|\+44)7(5|6|7|8|9){1}\d{2}\s?\d{6})$/); |
| 203 | }, 'Please specify a valid mobile number'); |
| 204 | |
| 205 | // TODO check if value starts with <, otherwise don't try stripping anything |
| 206 | jQuery.validator.addMethod("strippedminlength", function (value, element, param) { |
| 207 | return jQuery(value).text().length >= param; |
| 208 | }, jQuery.validator.format("Please enter at least {0} characters")); |
| 209 | |
| 210 | // same as email, but TLD is optional |
| 211 | jQuery.validator.addMethod("email2", function (value, element, param) { |
| 212 | 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); |
| 213 | }, jQuery.validator.messages.email); |
| 214 | |
| 215 | // same as url, but TLD is optional |
| 216 | jQuery.validator.addMethod("url2", function (value, element, param) { |
| 217 | 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); |
| 218 | }, jQuery.validator.messages.url); |
| 219 | |
| 220 | // NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator |
| 221 | // Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0 |
| 222 | // Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings) |
| 223 | jQuery.validator.addMethod("creditcardtypes", function (value, element, param) { |
| 224 | |
| 225 | if (/[^0-9-]+/.test(value)) |
| 226 | return false; |
| 227 | |
| 228 | value = value.replace(/\D/g, ""); |
| 229 | |
| 230 | var validTypes = 0x0000; |
| 231 | |
| 232 | if (param.mastercard) |
| 233 | validTypes |= 0x0001; |
| 234 | if (param.visa) |
| 235 | validTypes |= 0x0002; |
| 236 | if (param.amex) |
| 237 | validTypes |= 0x0004; |
| 238 | if (param.dinersclub) |
| 239 | validTypes |= 0x0008; |
| 240 | if (param.enroute) |
| 241 | validTypes |= 0x0010; |
| 242 | if (param.discover) |
| 243 | validTypes |= 0x0020; |
| 244 | if (param.jcb) |
| 245 | validTypes |= 0x0040; |
| 246 | if (param.unknown) |
| 247 | validTypes |= 0x0080; |
| 248 | if (param.all) |
| 249 | validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080; |
| 250 | |
| 251 | if (validTypes & 0x0001 && /^(51|52|53|54|55)/.test(value)) { //mastercard |
| 252 | return value.length == 16; |
| 253 | } |
| 254 | if (validTypes & 0x0002 && /^(4)/.test(value)) { //visa |
| 255 | return value.length == 16; |
| 256 | } |
| 257 | if (validTypes & 0x0004 && /^(34|37)/.test(value)) { //amex |
| 258 | return value.length == 15; |
| 259 | } |
| 260 | if (validTypes & 0x0008 && /^(300|301|302|303|304|305|36|38)/.test(value)) { //dinersclub |
| 261 | return value.length == 14; |
| 262 | } |
| 263 | if (validTypes & 0x0010 && /^(2014|2149)/.test(value)) { //enroute |
| 264 | return value.length == 15; |
| 265 | } |
| 266 | if (validTypes & 0x0020 && /^(6011)/.test(value)) { //discover |
| 267 | return value.length == 16; |
| 268 | } |
| 269 | if (validTypes & 0x0040 && /^(3)/.test(value)) { //jcb |
| 270 | return value.length == 16; |
| 271 | } |
| 272 | if (validTypes & 0x0040 && /^(2131|1800)/.test(value)) { //jcb |
| 273 | return value.length == 15; |
| 274 | } |
| 275 | if (validTypes & 0x0080) { //unknown |
| 276 | return true; |
| 277 | } |
| 278 | return false; |
| 279 | }, "Please enter a valid credit card number."); |
| 280 | |
| 281 | jQuery.validator.addMethod("ipv4", function (value, element, param) { |
| 282 | return this.optional(element) || /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/i.test(value); |
| 283 | }, "Please enter a valid IP v4 address."); |
| 284 | |
| 285 | jQuery.validator.addMethod("ipv6", function (value, element, param) { |
| 286 | 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); |
| 287 | }, "Please enter a valid IP v6 address."); |
| 288 | |
| 289 | /** |
| 290 | * Return true if the field value matches the given format RegExp |
| 291 | * |
| 292 | * @example jQuery.validator.methods.pattern("AR1004",element,/^AR\d{4}$/) |
| 293 | * @result true |
| 294 | * |
| 295 | * @example jQuery.validator.methods.pattern("BR1004",element,/^AR\d{4}$/) |
| 296 | * @result false |
| 297 | * |
| 298 | * @name jQuery.validator.methods.pattern |
| 299 | * @type Boolean |
| 300 | * @cat Plugins/Validate/Methods |
| 301 | */ |
| 302 | jQuery.validator.addMethod("pattern", function (value, element, param) { |
| 303 | return this.optional(element) || param.test(value); |
| 304 | }, "Invalid format."); |
| 305 | |
| 306 | // PX Custom Validator |
| 307 | jQuery.validator.addMethod("ssid", function (value, element, param) { |
| 308 | return this.optional(element) || (value.indexOf(" ") != 0 && value.lastIndexOf(" ") != (value.length - 1) && /^[0-9a-zA-Z!#\(\)\+\-\.\/%=\?@\^_\{|\}~\x20]{1,32}$/.test(value)); |
| 309 | }, "Please enter a valid SSID."); |
| 310 | |
| 311 | jQuery.validator.addMethod("ssid_ap", function (value, element, param) { |
| 312 | return this.optional(element) || !(/[,;"\\]/.test(value)); |
| 313 | }, "Please enter a valid SSID."); |
| 314 | |
| 315 | jQuery.validator.addMethod("name_check", function (value, element, param) { |
| 316 | return this.optional(element) || !(/[{}\|\[\]~`\\]/.test(value)); |
| 317 | }, "Please enter a valid name."); |
| 318 | |
| 319 | jQuery.validator.addMethod("phonenumber_check", function (value, element, param) { |
| 320 | return this.optional(element) || /^[\d#\*\+pe\?][\d#\*pe\?]{0,}$/.test(value); |
| 321 | }, "Please enter a valid phone number."); |
| 322 | |
| 323 | jQuery.validator.addMethod("sms_service_center_check", function (value, element, param) { |
| 324 | return this.optional(element) || /^[\+|00][\d]{1,}$/.test(value); |
| 325 | }, "Please enter a valid phone number."); |
| 326 | |
| 327 | jQuery.validator.addMethod("email_check", function (value, element, param) { |
| 328 | return this.optional(element) || /^\w+(-\w+)*(.\w+)*@\w+(-\w+)*(\.[\da-zA-Z]{2,3})+$/.test(value); |
| 329 | }, "Please enter a valid email."); |
| 330 | |
| 331 | jQuery.validator.addMethod("pin_check", function (value, element, param) { |
| 332 | return this.optional(element) || /^[0-9]{4,8}$/.test(value); |
| 333 | }, "Please enter a valid PIN code."); |
| 334 | |
| 335 | jQuery.validator.addMethod("puk_check", function (value, element, param) { |
| 336 | return this.optional(element) || /^[0-9]{8}$/.test(value); |
| 337 | }, "Please enter a valid PUK code."); |
| 338 | |
| 339 | jQuery.validator.addMethod("password_check", function (value, element, param) { |
| 340 | return this.optional(element) || /^[0-9a-zA-Z!#$*\+,\-\.%:=\?@\[\]\^_\{|\}~]{1,32}$/.test(value); |
| 341 | }, "Please enter a valid password."); |
| 342 | |
| 343 | jQuery.validator.addMethod("manage_info_check", function (value, element, param) { |
| 344 | return this.optional(element) || /^[0-9a-zA-Z!#$*\+,\-\.%:=\?@\[\]\^_\{|\}~]{1,32}$/.test(value); |
| 345 | }, "Please enter a valid password."); |
| 346 | |
| 347 | jQuery.validator.addMethod("secretcode_check", function (value, element, param) { |
| 348 | return this.optional(element) || /^[0-9a-zA-Z!#$*\+,\-\.%:=\?@\[\]\^_\{|\}~]{1,32}$/.test(value); |
| 349 | }, "Please enter a valid password."); |
| 350 | |
| 351 | jQuery.validator.addMethod("wps_pin_check", function (value, element, param) { |
| 352 | function validateChecksum(PIN) { |
| 353 | var accum = 0; |
| 354 | accum += 3 * (parseInt(PIN / 10000000) % 10); |
| 355 | accum += 1 * (parseInt(PIN / 1000000) % 10); |
| 356 | accum += 3 * (parseInt(PIN / 100000) % 10); |
| 357 | accum += 1 * (parseInt(PIN / 10000) % 10); |
| 358 | accum += 3 * (parseInt(PIN / 1000) % 10); |
| 359 | accum += 1 * (parseInt(PIN / 100) % 10); |
| 360 | accum += 3 * (parseInt(PIN / 10) % 10); |
| 361 | accum += 1 * (parseInt(PIN / 1) % 10); |
| 362 | return ((accum % 10) == 0); |
| 363 | } |
| 364 | |
| 365 | var result = value.length == 8 && validateChecksum(value); |
| 366 | return this.optional(element) || result; |
| 367 | }, "Invalid PIN number"); |
| 368 | |
| 369 | jQuery.validator.addMethod("wps_pin_length_check", function (value, element, param) { |
| 370 | return this.optional(element) || value.length == 4 || value.length == 8; |
| 371 | }); |
| 372 | jQuery.validator.addMethod("lanip_check", function (value, element, param) { |
| 373 | var isIp = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/i.test(value); |
| 374 | var result = false; |
| 375 | if(isIp) { |
| 376 | var iparr = value.split("."); |
| 377 | result = checkRange(iparr[0], 1, 223) && !checkRange(iparr[0], 127, 127) && checkRange(iparr[1], 0, 255) && checkRange(iparr[2], 0, 255) && checkRange(iparr[3], 1, 254); |
| 378 | } |
| 379 | |
| 380 | return this.optional(element) || result; |
| 381 | }); |
| 382 | |
| 383 | jQuery.validator.addMethod("comment_check", function (value, element, param) { |
| 384 | //not include space from 92/93 |
| 385 | return this.optional(element) || /^[0-9a-zA-Z!#\(\)\+\-\.\/%=\?@\^_\{|\}~]{1,32}$/.test(value); |
| 386 | }); |
| 387 | |
| 388 | jQuery.validator.addMethod("check_file_path", function(value, element, param) { |
| 389 | var result = true; |
| 390 | if (value.length != 1 && (value.charAt(0) == '/' && value.charAt(1) == '/')) { |
| 391 | result = false; |
| 392 | } |
| 393 | |
| 394 | var chars = [ '\\', ':', '*', '|', '#', '<', '>', '"', '?', "'", '&', '~', '`', '+' ]; |
| 395 | for ( var i = 0; i < value.length; i++) { |
| 396 | if ($.inArray(value[i], chars) != -1) { |
| 397 | result = false; |
| 398 | } |
| 399 | } |
| 400 | return this.optional(element) || result; |
| 401 | }); |
| 402 | |
| 403 | jQuery.validator.addMethod("portCompare", function (value, element, param) { |
| 404 | var endVal = parseInt(value, 10); |
| 405 | var startVal = parseInt($(param).val(), 10); |
| 406 | return param.indexOf("Start") != -1? startVal <= endVal : startVal >= endVal; |
| 407 | }); |
| 408 | |
| 409 | jQuery.validator.addMethod("mac_check", function (value, element, param) { |
| 410 | var isMac = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/.test(value); |
| 411 | if(isMac) { |
| 412 | var macArr = value.toUpperCase().split(':'); |
| 413 | var sub1 = '0x'+macArr[0]; |
| 414 | return !checkAllField(macArr, 'FF') && !checkAllField(macArr, '00') && ((sub1 & 1)!=1); |
| 415 | } |
| 416 | |
| 417 | function checkAllField(itemArr, value) { |
| 418 | return _.all(itemArr, function(item) { |
| 419 | return item == value; |
| 420 | }); |
| 421 | } |
| 422 | |
| 423 | return this.optional(element) || isMac; |
| 424 | }); |
| 425 | |
| 426 | jQuery.validator.addMethod("ip_check", function (value, element, param) { |
| 427 | var isIp = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/i.test(value); |
| 428 | var result = false; |
| 429 | if(isIp) { |
| 430 | var iparr = value.split("."); |
| 431 | result = checkRange(iparr[0], 1, 223) && checkRange(iparr[1], 0, 255) && checkRange(iparr[2], 0, 255) && checkRange(iparr[3], 1, 254); |
| 432 | } |
| 433 | |
| 434 | return this.optional(element) || result; |
| 435 | }); |
| 436 | |
| 437 | jQuery.validator.addMethod("dmz_ip_check", function (value, element, param) { |
| 438 | var isIp = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/i.test(value); |
| 439 | var result = false; |
| 440 | if(isIp) { |
| 441 | var iparr = value.split("."); |
| 442 | result = checkRange(iparr[0], 1, 255) && checkRange(iparr[1], 0, 255) && checkRange(iparr[2], 0, 255) && checkRange(iparr[3], 1, 254); |
| 443 | } |
| 444 | |
| 445 | return this.optional(element) || result; |
| 446 | }); |
| 447 | |
| 448 | jQuery.validator.addMethod("apn_check", function (value, element, param) { |
| 449 | if (value.charAt(0) == '.' || value.charAt(0) == '-' || value.charAt(value.length - 1) == '.' || value.charAt(value.length - 1) == '-') { |
| 450 | return false; |
| 451 | } |
| 452 | return this.optional(element) || (/^[0-9a-zA-Z\.-]{1,64}$/).test(value) && value.indexOf("($)") == -1; |
| 453 | }); |
| 454 | |
| 455 | jQuery.validator.addMethod("apn_profile_name_check", function (value, element, param) { |
| 456 | return this.optional(element) || (/^[0-9a-zA-Z\.!#\(\)\*\+%\-=\?@\[\]\^_\{\}\|~:, ]{1,30}$/).test(value) && value.indexOf("($)") == -1; |
| 457 | }); |
| 458 | |
| 459 | jQuery.validator.addMethod("ppp_username_check", function (value, element, param) { |
| 460 | return this.optional(element) || (/^[0-9a-zA-Z!#$&()*\+,\-\.\/%:;<=>?@\[\]^_\{|\}~ ]*$/.test(value) && value.indexOf("($)") == -1); |
| 461 | }); |
| 462 | jQuery.validator.addMethod("ppp_password_check", function (value, element, param) { |
| 463 | return this.optional(element) || (/^[0-9a-zA-Z!#$&()*\+,\-\.\/%:;<=>?@\[\]^_\{|\}~ ]*$/.test(value) && value.indexOf("($)") == -1); |
| 464 | }); |
| 465 | jQuery.validator.addMethod("ppp_secretcode_check", function (value, element, param) { |
| 466 | return this.optional(element) || (/^[0-9a-zA-Z!#$&()*\+,\-\.\/%:;<=>?@\[\]^_\{|\}~ ]*$/.test(value) && value.indexOf("($)") == -1); |
| 467 | }); |
| 468 | jQuery.validator.addMethod("unlock_code_check", function (value, element, param) { |
| 469 | return this.optional(element) || /^[0-9a-fA-F]{16}/.test(value); |
| 470 | }); |
| 471 | |
| 472 | jQuery.validator.addMethod("wifi_password_check", function (value, element, param) { |
| 473 | return this.optional(element) || /^[0-9a-zA-Z!#\(\)\+\-\.\/%=\?@\^_\{|\}~]*$/.test(value); |
| 474 | }); |
| 475 | jQuery.validator.addMethod("wifi_wep_password_check", function (value, element, param) { |
| 476 | return this.optional(element) || /^([0-9A-Fa-f]{10}|[0-9A-Fa-f]{26}|[\x00-\x7f]{5}|[\x00-\x7f]{13})$/.test(value); |
| 477 | }); |
| 478 | jQuery.validator.addMethod("range_except", function (value, element, param) { |
| 479 | return this.optional(element) || (( value >= param[0] && value < 32000 )||( value > 32007 && value <= param[1] )); |
| 480 | }); |
| 481 | jQuery.validator.addMethod("any_digits", function (value, element, param) { |
| 482 | return this.optional(element) || /^\d+$/.test(value); |
| 483 | }); |
| 484 | |
| 485 | jQuery.validator.addMethod("sntp_invalid_server_name", function(value, element, param){ |
| 486 | 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) || /^[a-zA-Z0-9](-?[a-zA-Z0-9]){0,62}(\.[a-zA-Z0-9](-?[a-zA-Z0-9]){0,62})+$/.test(value); |
| 487 | }); |
| 488 | jQuery.validator.addMethod("url_check", function(value, element, param){ |
| 489 | var strRegex = "^((https|http|ftp|rtsp|mms)?://)" |
| 490 | + "?(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-zA-Z_!~*'().&=+$%-]+@)?" //ftp的user@ |
| 491 | + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184 |
| 492 | + "|" // 允许IP和DOMAIN(域名) |
| 493 | + "([0-9a-zA-Z_!~*'()-]+\.)*" // 域名- www. |
| 494 | + "([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\." // 二级域名 |
| 495 | + "[a-zA-Z]{2,6})" // first level domain- .com or .museum |
| 496 | + "(:[0-9]{1,4})?" // 端口- :80 |
| 497 | + "((/?)|" |
| 498 | + "(/[0-9a-zA-Z_!~*'().;?:@&=+$,%#-]+)+/?)$"; |
| 499 | var re=new RegExp(strRegex); |
| 500 | |
| 501 | return this.optional(element) ||re.test(value); ; |
| 502 | //^[a-zA-Z0-9](-?[a-zA-Z0-9]){0,62}(\.[a-zA-Z0-9](-?[a-zA-Z0-9]){0,62})+$/.test(value); |
| 503 | }); |
| 504 | jQuery.validator.addMethod("url_filter_check", function(value, element, param){ |
| 505 | var strRegex = "^((http|ftp|rtsp|mms)?://)" |
| 506 | + "?(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-zA-Z_!~*'().&=+$%-]+@)?" //ftp的user@ |
| 507 | + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184 |
| 508 | + "|" // 允许IP和DOMAIN(域名) |
| 509 | + "([0-9a-zA-Z_!~*'()-]+\.)*" // 域名- www. |
| 510 | + "([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\." // 二级域名 |
| 511 | + "[a-zA-Z]{2,6})" // first level domain- .com or .museum |
| 512 | + "(:[0-9]{1,4})?" // 端口- :80 |
| 513 | + "((/?)|" |
| 514 | + "(/[0-9a-zA-Z_!~*'().;?:@&=+$,%#-]+)+/?)$"; |
| 515 | var re=new RegExp(strRegex); |
| 516 | |
| 517 | return this.optional(element) ||re.test(value); ; |
| 518 | //^[a-zA-Z0-9](-?[a-zA-Z0-9]){0,62}(\.[a-zA-Z0-9](-?[a-zA-Z0-9]){0,62})+$/.test(value); |
| 519 | }); |
| 520 | jQuery.validator.addMethod("voip_outbound_port_check", function(value, element, param){ |
| 521 | var isNum = /^[0-9]{4,5}$/.test(value); |
| 522 | var result = false; |
| 523 | if(isNum) { |
| 524 | if(parseInt(value) >= 1024 && parseInt(value) <= 65535) { |
| 525 | return true; |
| 526 | } |
| 527 | } |
| 528 | return this.optional(element) || result; |
| 529 | }); |
| 530 | jQuery.validator.addMethod("voip_time_check", function(value, element, param){ |
| 531 | var isNum = /^[0-9]{1,4}$/.test(value); |
| 532 | var result = false; |
| 533 | if(isNum) { |
| 534 | if(parseInt(value) >= 1 && parseInt(value) <= 3600) { |
| 535 | return true; |
| 536 | } |
| 537 | } |
| 538 | return this.optional(element) || result; |
| 539 | }); |
| 540 | jQuery.validator.addMethod("voip_sip_port_check", function(value, element, param){ |
| 541 | var isNum = /^[0-9]{4,5}$/.test(value); |
| 542 | var result = false; |
| 543 | if(isNum) { |
| 544 | if(parseInt(value) >= 1026 && parseInt(value) <= 65535) { |
| 545 | return true; |
| 546 | } |
| 547 | } |
| 548 | return this.optional(element) || result; |
| 549 | }); |
| 550 | jQuery.validator.addMethod("voip_port_compare", function(value, element, param){ |
| 551 | var maxVal = parseInt(value, 10); |
| 552 | var minVal = parseInt($(param).val(), 10); |
| 553 | return param.indexOf("min") != -1? minVal <= maxVal : minVal >= maxVal; |
| 554 | }); |
| 555 | jQuery.validator.addMethod("sip_domain_check", function (value, element, param) { |
| 556 | return this.optional(element)|| /^[a-zA-Z0-9](-?[a-zA-Z0-9]){0,62}(\.[a-zA-Z0-9](-?[a-zA-Z0-9]){0,62})+$/.test(value); |
| 557 | }); |
| 558 | jQuery.validator.addMethod("sip_realm_check", function (value, element, param) { |
| 559 | return this.optional(element)|| /^[0-9a-zA-Z.@:+-;?=%&]+$/.test(value); |
| 560 | }); |
| 561 | jQuery.validator.addMethod("sip_proxy_server_check", function (value, element, param) { |
| 562 | return this.optional(element)|| /^[0-9a-zA-Z.@:+-;?=%&]+$/.test(value); |
| 563 | }); |
| 564 | jQuery.validator.addMethod("display_name_check", function (value, element, param) { |
| 565 | return this.optional(element)|| /^[0-9a-zA-Z.@:+-;?=%&]+$/.test(value); |
| 566 | }); |
| 567 | jQuery.validator.addMethod("authorized_username_check", function (value, element, param) { |
| 568 | return this.optional(element)|| /^[0-9a-zA-Z.@:+-;?=%&]+$/.test(value); |
| 569 | }); |
| 570 | jQuery.validator.addMethod("account_password_check", function (value, element, param) { |
| 571 | return this.optional(element)|| /^[0-9a-zA-Z.@:+-;?=%&]+$/.test(value); |
| 572 | }); |
| 573 | jQuery.validator.addMethod("forwarding_uri_check", function (value, element, param) { |
| 574 | var unicodeReg = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi; |
| 575 | if(unicodeReg.test(value)) { |
| 576 | return false; |
| 577 | } else { |
| 578 | return /^[0-9\*#\+]+$/.test(value); |
| 579 | } |
| 580 | }); |
| 581 | jQuery.validator.addMethod("login_password_length_check", function (value, element, param) { |
| 582 | return this.optional(element) || value.length >= 4; |
| 583 | }); |
| 584 | |
| 585 | jQuery.validator.addMethod("equalToPin", function (value, element, param) { |
| 586 | return this.optional(element) || value == $(param).val(); |
| 587 | }); |
| 588 | |
| 589 | jQuery.validator.addMethod("equalToPassword", function (value, element, param) { |
| 590 | return this.optional(element) || value == $(param).val(); |
| 591 | }); |
| 592 | |
| 593 | jQuery.validator.addMethod("equalTo", function (value, element, param) { |
| 594 | return this.optional(element) || value == $(param).val(); |
| 595 | }); |
| 596 | |
| 597 | jQuery.validator.addMethod("wps_pin_validator", function (value, element, param) { |
| 598 | return this.optional(element) || /^\d{4}$/.test(value) || /^\d{8}$/.test(value) || /^\d{4}[ -]\d{4}$/.test(value); |
| 599 | }); |
| 600 | |
| 601 | jQuery.validator.addMethod("decimalRange", function (value, element, param) { |
| 602 | return this.optional(element) || /^(0|[1-9]\d*)(\.\d{1,2})?$/.test(value); |
| 603 | }); |
| 604 | |
| 605 | jQuery.validator.addMethod("ddns_hashvalue_check", function (value, element, param) { |
| 606 | return this.optional(element) || /^[0-9a-zA-Z=]*$/.test(value); |
| 607 | }); |
| 608 | |
| 609 | jQuery.validator.addMethod("siteName_check", function (value, element, param) { |
| 610 | var isSiteName = /[\*\$\[&:,;<>'"\\`\]¥\|\?\/]{1,32}/.test(value); |
| 611 | return this.optional(element) || !isSiteName; |
| 612 | }); |
| 613 | |
| 614 | jQuery.validator.addMethod("siteLink_check", function (value, element, param) { |
| 615 | var isSiteName = /^(https?):\/\/(((([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); |
| 616 | return this.optional(element) || isSiteName; |
| 617 | }); |