PageSourceSearch

https://standbeelden.be/js/jquery.validate.additional-methods.js

js standbeelden.be collected 2026-10-02 07:05:13 UTC 8,092 bytes, 173 lines download raw bytes

1jQuery.validator.addMethod("maxWords", function(value, element, params) { 
2    return this.optional(element) || value.match(/\b\w+\b/g).length < params; 
3}, "Please enter {0} words or less."); 
4 
5jQuery.validator.addMethod("minWords", function(value, element, params) { 
6    return this.optional(element) || value.match(/\b\w+\b/g).length >= params; 
7}, "Please enter at least {0} words."); 
8 
9jQuery.validator.addMethod("rangeWords", function(value, element, params) { 
10    return this.optional(element) || value.match(/\b\w+\b/g).length >= params[0] && value.match(/bw+b/g).length < params[1]; 
11}, "Please enter between {0} and {1} words.");
12
13
14jQuery.validator.addMethod("letterswithbasicpunc", function(value, element) {
15	return this.optional(element) || /^[a-z-.,()'\"\s]+$/i.test(value);
16}, "Letters or punctuation only please");  
17
18jQuery.validator.addMethod("alphanumeric", function(value, element) {
19	return this.optional(element) || /^\w+$/i.test(value);
20}, "Letters, numbers, spaces or underscores only please");  
21
22jQuery.validator.addMethod("lettersonly", function(value, element) {
23	return this.optional(element) || /^[a-z]+$/i.test(value);
24}, "Letters only please");
25
26jQuery.validator.addMethod("nonumbers", function(str, element) {
27	return this.optional(element) || /^[a-zA-Z-_' \u00A1-\uFFFF]+$/i.test(str);
28}, "Letters only please");
29
30jQuery.validator.addMethod("username", function(str, element) {
31	return this.optional(element) || /^[a-zA-Z-_'\u00A1-\uFFFF]+$/i.test(str);
32}, "Letters only please");
33
34jQuery.validator.addMethod("nowhitespace", function(value, element) {
35	return this.optional(element) || /^\S+$/i.test(value);
36}, "No white space please"); 
37
38jQuery.validator.addMethod("ziprange", function(value, element) {
39	return this.optional(element) || /^90[2-5]\d\{2}-\d{4}$/.test(value);
40}, "Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx");
41
42/**
43* Return true, if the value is a valid vehicle identification number (VIN).
44*
45* Works with all kind of text inputs.
46*
47* @example <input type="text" size="20" name="VehicleID" class="{required:true,vinUS:true}" />
48* @desc Declares a required input element whose value must be a valid vehicle identification number.
49*
50* @name jQuery.validator.methods.vinUS
51* @type Boolean
52* @cat Plugins/Validate/Methods
53*/ 
54jQuery.validator.addMethod(
55	"vinUS",
56	function(v){
57		if (v.length != 17)
58			return false;
59		var i, n, d, f, cd, cdv;
60		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"];
61		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];
62		var FL    = [8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2];
63		var rs    = 0;
64		for(i = 0; i < 17; i++){
65		    f = FL[i];
66		    d = v.slice(i,i+1);
67		    if(i == 8){
68		        cdv = d;
69		    }
70		    if(!isNaN(d)){
71		        d *= f;
72		    }
73		    else{
74		        for(n = 0; n < LL.length; n++){
75		            if(d.toUpperCase() === LL[n]){
76		                d = VL[n];
77		                d *= f;
78		                if(isNaN(cdv) && n == 8){
79		                    cdv = LL[n];
80		                }
81		                break;
82		            }
83		        }
84		    }
85		    rs += d;
86		}
87		cd = rs % 11;
88		if(cd == 10){cd = "X";}
89		if(cd == cdv){return true;}
90		return false; 
91	},
92	"The specified vehicle identification number (VIN) is invalid."
93);
94
95/**
96  * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy.
97  *
98  * @example jQuery.validator.methods.date("01/01/1900")
99  * @result true
100  *
101  * @example jQuery.validator.methods.date("01/13/1990")
102  * @result false
103  *
104  * @example jQuery.validator.methods.date("01.01.1900")
105  * @result false
106  *
107  * @example <input name="pippo" class="{dateITA:true}" />
108  * @desc Declares an optional input element whose value must be a valid date.
109  *
110  * @name jQuery.validator.methods.dateITA
111  * @type Boolean
112  * @cat Plugins/Validate/Methods
113  */
114jQuery.validator.addMethod(
115	"dateITA",
116	function(value, element) {
117		var check = false;
118		var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/
119		if( re.test(value)){
120			var adata = value.split('/');
121			var gg = parseInt(adata[0],10);
122			var mm = parseInt(adata[1],10);
123			var aaaa = parseInt(adata[2],10);
124			var xdata = new Date(aaaa,mm-1,gg);
125			if ( ( xdata.getFullYear() == aaaa ) && ( xdata.getMonth () == mm - 1 ) && ( xdata.getDate() == gg ) )
126				check = true;
127			else
128				check = false;
129		} else
130			check = false;
131		return this.optional(element) || check;
132	}, 
133	"Please enter a correct date"
134);
135
136/**
137 * matches US phone number format 
138 * 
139 * where the area code may not start with 1 and the prefix may not start with 1 
140 * allows '-' or ' ' as a separator and allows parens around area code 
141 * some people may want to put a '1' in front of their number 
142 * 
143 * 1(212)-999-2345
144 * or
145 * 212 999 2344
146 * or
147 * 212-999-0983
148 * 
149 * but not
150 * 111-123-5434
151 * and not
152 * 212 123 4567
153 */
154jQuery.validator.addMethod("phone", function(phone_number, element) {
155    phone_number = phone_number.replace(/\s+/g, ""); 
156	return this.optional(element) || phone_number.length > 9 &&
157		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
158}, "Please specify a valid phone number");
159
160// TODO check if value starts with <, otherwise don't try stripping anything
161jQuery.validator.addMethod("strippedminlength", function(value, element, param) {
162	return jQuery(value).text().length >= param;
163}, jQuery.format("Please enter at least {0} characters"));
164
165// same as email, but TLD is optional
166jQuery.validator.addMethod("email2", function(value, element, param) {
167	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); 
168}, jQuery.validator.messages.email);
169
170// same as url, but TLD is optional
171jQuery.validator.addMethod("url2", function(value, element, param) {
172	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); 
173}, jQuery.validator.messages.url);

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.