PageSourceSearch

https://mssociety.org.il/wp-content/plugins/jquery-validation-for-…/assets/js/jvcf7p_validation.js?ver=5.2

js mssociety.org.il collected 2026-10-05 20:08:48 UTC 9,309 bytes, 232 lines download raw bytes

1// VALIDATION CODES
2jQuery(document).ready(function(){
3	
4	jQuery('.wpcf7-validates-as-required').addClass('required');
5	jQuery('.wpcf7-email').addClass('email');
6	jQuery('.wpcf7-checkbox.wpcf7-validates-as-required input').addClass('required');
7	jQuery('.wpcf7-radio input').addClass('required');
8	
9	jQuery('form.wpcf7-form').each(function(){
10		jQuery(this).addClass(scriptData.jvcf7p_default_settings.jvcf7p_invalid_field_design);
11		jQuery(this).addClass(scriptData.jvcf7p_default_settings.jvcf7p_show_label_error);
12		jQuery('.wpcf7-file').attr('accept','');
13		jQuery(this).validate({
14			errorPlacement: function(error, element) {
15	            if (element.is(':checkbox') || element.is(':radio')){
16	            	error.insertAfter(jQuery(element).parent().parent().parent());
17	            } else {
18	            	error.insertAfter(element);
19	            }
20         	}
21		});
22	});
23
24	jQuery('.wpcf7-form-control.wpcf7-submit').click(function(e){ 
25		$jvcfpValidation 	=	jQuery(this).parents('form');
26		
27		if (jQuery($jvcfpValidation).validate().pendingRequest != 0){ // is Remote Call is Pending
28			e.preventDefault();
29			$topPendingPosition 		= jQuery('.wpcf7-form-control.pending').offset().top;
30			$topPendingPosition			= parseInt($topPendingPosition) - 100;
31			jQuery('body, html').animate({scrollTop:$topPendingPosition}, 'normal');
32		}
33		
34		if (!jQuery($jvcfpValidation).valid()){ // If form invalid
35			e.preventDefault();
36			$topErrorPosition 		= jQuery('.wpcf7-form-control.error').offset().top;
37			$topErrorPosition		= parseInt($topErrorPosition) - 100;
38			jQuery('body, html').animate({scrollTop:$topErrorPosition}, 'normal');
39		}
40	});
41	
42	jQuery('[class*="JVmin-"]').each(function(){ // Min
43		allClasser = jQuery(this).attr('class');
44		processingClass 		= allClasser.match(/JVmin-[0-9]+/);
45		var processingClassSplit	= processingClass.toString().split("-");
46		jQuery(this).attr('min',processingClassSplit[1]);
47	});
48	
49	jQuery('[class*="JVmax-"]').each(function(){ // Max
50		allClasser = jQuery(this).attr('class');
51		processingClass 		= allClasser.match(/JVmax-[0-9]+/);
52		var processingClassSplit	= processingClass.toString().split("-");
53		jQuery(this).attr('max',processingClassSplit[1]);
54	});
55	
56	jQuery('[class*="JVminlength-"]').each(function(){ // Minlength
57		allClasser = jQuery(this).attr('class');
58		processingClass 		= allClasser.match(/JVminlength-[0-9]+/);
59		var processingClassSplit	= processingClass.toString().split("-");
60		jQuery(this).rules( "add", {minlength: processingClassSplit[1]});
61	});
62	
63	jQuery('[class*="JVmaxlength-"]').each(function(){ // Maxlength
64		allClasser = jQuery(this).attr('class');
65		processingClass 			= allClasser.match(/JVmaxlength-[0-9]+/);
66		var processingClassSplit	= processingClass.toString().split("-");
67		jQuery(this).rules( "add", {maxlength: processingClassSplit[1]});
68	});
69	
70	jQuery('[class*="JVrangelength-"]').each(function(){ // rangelength
71		allClasser = jQuery(this).attr('class');
72		processingClass 			= allClasser.match(/JVrangelength-[0-9]+-[0-9]+/);
73		var processingClassSplit	= processingClass.toString().split("-");
74		jQuery(this).rules( "add", {rangelength: [processingClassSplit[1],processingClassSplit[2] ]});
75	});
76	
77	jQuery('[class*="JVrange-"]').each(function(){ // range
78		allClasser = jQuery(this).attr('class');
79		processingClass 			= allClasser.match(/JVrange-[0-9]+-[0-9]+/);
80		var processingClassSplit	= processingClass.toString().split("-");
81		jQuery(this).rules( "add", {range: [processingClassSplit[1],processingClassSplit[2] ]});
82	});
83	
84	jQuery('[class*="JVequalTo-"]').each(function(){ // range
85		allClasser = jQuery(this).attr('class');
86		processingClass 			= allClasser.match(/JVequalTo-[a-zA-Z0-9-_]+/);
87		var processingClassSplit	= processingClass.toString().split("To-");
88		jQuery(this).rules( "add", {equalTo: "[name="+processingClassSplit[1]+"]" });
89	});
90	
91	jQuery('[class*="JVextension-"]').each(function(){ // range
92		allClasser = jQuery(this).attr('class');
93		processingClass 				= allClasser.match(/JVextension-[a-zA-Z0-9-_]+/);
94		var processingClassSplit		= processingClass.toString().split("extension-");
95		var processingExtensionSplit	= processingClassSplit[1].toString().split("_");
96		var extnesions 					= processingExtensionSplit.join('|');
97		jQuery(this).rules( "add", {extension: extnesions });		
98	});
99		
100	jQuery('[class*="JVrequireGroup-"]').each(function(){ // range
101		allClasser = jQuery(this).attr('class');
102		processingClass 				= allClasser.match(/JVrequireGroup-[a-zA-Z0-9-_]+/);
103		var processingClassSplit		= processingClass.toString().split("requireGroup-");
104		var processingCountClassSplit	= processingClassSplit[1].toString().split("_");
105		jQuery(this).addClass(processingCountClassSplit[1]);
106		jQuery(this).rules( "add", {require_from_group: [processingCountClassSplit[0], "."+processingCountClassSplit[1]] });		
107	});
108
109	jQuery('input.checkUsername').each(function(){
110		jQuery(this).rules( "add", {
111			"remote": {
112				'url'  : scriptData.jvcf7p_ajax_url,
113				'type' : "post",
114				'data' : {
115					"method":"checkUsername",
116					"fieldname" : jQuery(this).attr('name')
117				}
118			}
119		});
120	});
121
122	jQuery('input.customCode').each(function(){
123		jQuery(this).rules( "add", {
124			"remote": {
125				'url'  : scriptData.jvcf7p_ajax_url,
126				'type' : "post",
127				'data' : {
128					"method":"customCode_deprecated",
129					"fieldname" : jQuery(this).attr('name')
130				}
131			}
132		});
133	});
134
135	jQuery('[class*="CCode-"]').each(function(){ // NEW MULTI CUSTOM CODE
136		allClasser = jQuery(this).attr('class');
137		processingClass 				= allClasser.match(/CCode-[0-9]+/);
138		var processingClassSplit		= processingClass.toString().split("-");
139		CustomValidatonID 				= processingClassSplit[1];
140
141		jQuery(this).rules( "add", {
142			"remote": {
143				'url'  : scriptData.jvcf7p_ajax_url,
144				'type' : "post",
145				'data' : {
146					"method"				: "customCode",
147					"fieldname" 			: jQuery(this).attr('name'),
148					"custom_validation_id"	: CustomValidatonID
149				}
150			}
151		});
152	});
153
154	// EMAIL VERIFICATION
155	jQuery('input.emailVerify').each(function(){		
156		elementName  	= jQuery(this).attr('name');
157		elementSize		= jQuery(this).outerWidth();
158		saveButton 		= '<span style="width:'+elementSize+'px;" class="verification_code_holder"><input type="text" name="email-verification-code" data-for="'+elementName+'" class="wpcf7-form-control wpcf7-text verifyEmailCode required" value="" placeholder="'+scriptData.jvcf7p_default_settings.jvcf7p_verify_code_field_placeholder+'" /><input type="button" class="jvcf7_verify_email_btn" value="Send Code" data-for="'+elementName+'" id="jvcf7_verify_email_btn" style="display:none;" /></span>';
159		jQuery(saveButton).insertAfter(this);
160
161		
162		jQuery('.verifyEmailCode').rules( "add", {
163			'required':true,
164			"remote": {
165				'url'  : scriptData.jvcf7p_ajax_url,
166				'type' : "post",
167				'data' : {
168					"method":"verifyEmailCode",
169					"fieldname" : "email-verification-code",
170					"email" 	: function (){return jQuery('input[name='+elementName+']').val();}
171
172				}
173			}
174		});
175		jQuery('.jvcf7_verify_email_btn').show();
176	});
177
178	jQuery('input.jvcf7_verify_email_btn').click(function(){
179			 fieldname = jQuery(this).attr('data-for');
180			 if (jQuery("input[name="+fieldname+"]").valid() == true){
181				 jQuery.ajax({
182				 	url  : scriptData.jvcf7p_ajax_url,
183				 	context:this,
184				 	type : "post",
185					data : {
186								"method"			: "sendVerificationCode",
187								"email" 			: jQuery("input[name="+fieldname+"]").val()
188							 },
189				    beforeSend: function() {
190				        jQuery(this).removeClass('valid');
191				        jQuery(this).attr('value','Sending..');			        
192				    },
193				    success: function(data) {
194				      	jQuery(this).removeClass('valid');
195				      	jQuery(this).attr('value','Resend Code');			      	
196					},
197				    error: function() {
198				    	jQuery(this).removeClass('valid');
199				    	jQuery(this).attr('value','Error !');
200				    }
201				  });
202			} else {
203				jQuery("input[name="+fieldname+"]").focus();
204			}
205
206	});
207});
208
209jQuery.validator.addMethod("email", 
210    function(value, element) {
211        return this.optional(element) || /^[+\w-\.]+@([\w-]+\.)+[\w-]{2,10}$/i.test(value);
212    },"Please enter a valid email address"
213);
214
215jQuery.validator.addMethod("letters_space", function(value, element) {
216  return this.optional(element) || /^[a-zA-Z ]*$/.test(value);
217}, "Letters and space only");
218
219jQuery.validator.addMethod("stateUS", function (state, element) {
220    return this.optional(element) || state.match(/^(A[LKSZRAEP]|C[AOT]|D[EC]|F[LM]|G[ANU]|HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$/);
221}, "Please specify a valid state");
222
223var regExs = [];
224for (const validationID in scriptData.jvcf7p_regexs) {
225	regExs[validationID] = new RegExp(scriptData.jvcf7p_regexs[validationID].regex,'i');
226  	errorMsg  	= scriptData.jvcf7p_regexs[validationID].error_mg;
227  	jQuery.validator.addMethod("RegEx-"+validationID, function(value, element) {
228	  return this.optional(element) || regExs[validationID].test(value);
229	}, errorMsg );
230}
231
232jQuery.extend(jQuery.validator.messages,scriptData.jvcf7p_default_error_msgs);

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.