PageSourceSearch

https://www.hotelflamingo.it/wp-content/plugins/mybooking-rf/contact-form/scripts/gen_validatorv31.js?ver=4.0

js hotelflamingo.it collected 2026-10-04 13:26:09 UTC 20,110 bytes, 823 lines download raw bytes

1/*
2  -------------------------------------------------------------------------
3            JavaScript Form Validator (gen_validatorv31.js)
4              Version 3.1
5   Copyright (C) 2003-2008 JavaScript-Coder.com. All rights reserved.
6   You can freely use this script in your Web pages.
7   You may adapt this script for your own needs, provided these opening credit
8    lines are kept intact.
9      
10   The Form validation script is distributed free from JavaScript-Coder.com
11   For updates, please visit:
12   http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
13   
14   Questions & comments please send to [email protected]
15  -------------------------------------------------------------------------  
16*/
17function Validator(frmname,ajaxForm)
18{
19  if(typeof ajaxForm === "undefined")
20	  ajaxForm = false;
21  this.formobj=document.forms[frmname];
22   if(!this.formobj)
23   {
24     alert("Error: couldnot get Form object "+frmname);
25      return;
26   }
27   if(this.formobj.onsubmit)
28   {
29    this.formobj.old_onsubmit = this.formobj.onsubmit;
30    this.formobj.onsubmit=null;
31   }
32   else
33   {
34    this.formobj.old_onsubmit = null;
35   }
36   this.formobj._sfm_form_name=frmname;
37   if(!ajaxForm) {
38	   this.formobj.onsubmit=form_submit_handler;
39   }
40   this.addValidation = add_validation;
41   this.setAddnlValidationFunction=set_addnl_vfunction;
42   this.clearAllValidations = clear_all_validations;
43    this.disable_validations = false;//new
44    document.error_disp_handler = new sfm_ErrorDisplayHandler();
45    this.EnableOnPageErrorDisplay=validator_enable_OPED;
46   this.EnableOnPageErrorDisplaySingleBox=validator_enable_OPED_SB;
47    this.show_errors_together=true;
48    this.EnableMsgsTogether=sfm_enable_show_msgs_together;
49}
50function set_addnl_vfunction(functionname)
51{
52  this.formobj.addnlvalidation = functionname;
53}
54function sfm_enable_show_msgs_together()
55{
56    this.show_errors_together=true;
57    this.formobj.show_errors_together=true;
58}
59function clear_all_validations()
60{
61   for(var itr=0;itr < this.formobj.elements.length;itr++)
62   {
63      this.formobj.elements[itr].validationset = null;
64   }
65}
66function form_submit_handler()
67{
68	try{
69	   var bRet = true;
70	    document.error_disp_handler.clear_msgs();
71	   for(var itr=0;itr < this.elements.length;itr++)
72	   {
73	      if(this.elements[itr].validationset &&
74	      !this.elements[itr].validationset.validate())
75	      {
76	        bRet = false;
77	      }
78	        if(!bRet && !this.show_errors_together)
79	        {
80	          break;
81	        }
82	   }
83	    if(!bRet)
84	    {
85	      document.error_disp_handler.FinalShowMsg();
86	      return false;
87	    }
88	
89	   if(this.addnlvalidation)
90	   {
91	     str =" var ret = "+this.addnlvalidation+"()";
92	     eval(str);
93	    if(!ret) return ret;
94	   }
95	   return true;
96	}
97	catch(e){
98		alert(e);
99		return false;
100	}
101}
102function add_validation(itemname,descriptor,errstr)
103{
104   var condition = null;
105   if(arguments.length > 3)
106   {
107    condition = arguments[3]; 
108   }
109  if(!this.formobj)
110   {
111      alert("Error: The form object is not set properly");
112      return;
113   }//if
114   var itemobj = this.formobj[itemname];
115    if(itemobj!=null && itemobj.length && isNaN(itemobj.selectedIndex) )
116    //for radio button; don't do for 'select' item
117   {
118      itemobj = itemobj[0];
119   }  
120  if(!itemobj)
121   {
122      alert("Error: Couldnot get the input object named: "+itemname);
123      return;
124   }
125   if(!itemobj.validationset)
126   {
127      itemobj.validationset = new ValidationSet(itemobj,this.show_errors_together);
128   }
129   itemobj.validationset.add(descriptor,errstr,condition);
130    itemobj.validatorobj=this;
131}
132function validator_enable_OPED()
133{
134    document.error_disp_handler.EnableOnPageDisplay(false);
135}
136
137function validator_enable_OPED_SB()
138{
139   document.error_disp_handler.EnableOnPageDisplay(true);
140}
141function sfm_ErrorDisplayHandler()
142{
143  this.msgdisplay = new AlertMsgDisplayer();
144  this.EnableOnPageDisplay= edh_EnableOnPageDisplay;
145  this.ShowMsg=edh_ShowMsg;
146  this.FinalShowMsg=edh_FinalShowMsg;
147  this.all_msgs=new Array();
148  this.clear_msgs=edh_clear_msgs;
149}
150function edh_clear_msgs()
151{
152    this.msgdisplay.clearmsg(this.all_msgs);
153    this.all_msgs = new Array();
154}
155function edh_FinalShowMsg()
156{
157    this.msgdisplay.showmsg(this.all_msgs);
158}
159function edh_EnableOnPageDisplay(single_box)
160{
161   if(true == single_box)
162   {
163      this.msgdisplay = new SingleBoxErrorDisplay();
164   }
165   else
166   {
167      this.msgdisplay = new DivMsgDisplayer();     
168   }
169}
170function edh_ShowMsg(msg,input_element)
171{
172   
173   var objmsg = new Array();
174   objmsg["input_element"] = input_element;
175   objmsg["msg"] =  msg;
176   this.all_msgs.push(objmsg);
177}
178function AlertMsgDisplayer()
179{
180  this.showmsg = alert_showmsg;
181  this.clearmsg=alert_clearmsg;
182}
183function alert_clearmsg(msgs)
184{
185
186}
187function alert_showmsg(msgs)
188{
189    var whole_msg="";
190    var first_elmnt=null;
191    for(var m in msgs)
192    {
193        if(null == first_elmnt)
194        {
195            first_elmnt = msgs[m]["input_element"];
196        }
197        whole_msg += msgs[m]["msg"] + "\n";
198    }
199   
200    alert(whole_msg);
201
202    if(null != first_elmnt)
203    {
204        first_elmnt.focus();
205    }
206}
207function sfm_show_error_msg(msg,input_elmt)
208{
209    document.error_disp_handler.ShowMsg(msg,input_elmt);
210}
211function SingleBoxErrorDisplay()
212{
213 this.showmsg=sb_div_showmsg;
214 this.clearmsg=sb_div_clearmsg;
215}
216
217function sb_div_clearmsg(msgs)
218{
219   var divname = form_error_div_name(msgs);
220   show_div_msg(divname,"");
221}
222
223function sb_div_showmsg(msgs)
224{
225   var whole_msg="<ul>\n";
226   for(var m in msgs)
227    {
228        whole_msg += "<li>" + msgs[m]["msg"] + "</li>\n";
229    }
230   whole_msg += "</ul>";
231   var divname = form_error_div_name(msgs);
232   show_div_msg(divname,whole_msg);
233}
234function form_error_div_name(msgs)
235{
236   var input_element= null;
237
238   for(var m in msgs)
239   {
240    input_element = msgs[m]["input_element"];
241    if(input_element){break;}
242   }
243
244   var divname ="";
245   if(input_element)
246   {
247    divname = input_element.form._sfm_form_name + "_errorloc";
248   }
249
250   return divname;
251}
252function DivMsgDisplayer()
253{
254 this.showmsg=div_showmsg;
255 this.clearmsg=div_clearmsg;
256}
257function div_clearmsg(msgs)
258{
259    for(var m in msgs)
260    {
261        var divname = element_div_name(msgs[m]["input_element"]);
262        show_div_msg(divname,"");
263    }
264}
265function element_div_name(input_element)
266{
267  var divname = input_element.form._sfm_form_name + "_" + 
268                   input_element.name + "_errorloc";
269
270  divname = divname.replace(/[\[\]]/gi,"");
271
272  return divname;
273}
274function div_showmsg(msgs)
275{
276    var whole_msg;
277    var first_elmnt=null;
278    for(var m in msgs)
279    {
280        if(null == first_elmnt)
281        {
282            first_elmnt = msgs[m]["input_element"];
283        }
284        var divname = element_div_name(msgs[m]["input_element"]);
285        show_div_msg(divname,msgs[m]["msg"]);
286    }
287    if(null != first_elmnt)
288    {
289        first_elmnt.focus();
290    }
291}
292function show_div_msg(divname,msgstring)
293{
294   if(divname.length<=0) return false;
295
296   if(document.layers)
297   {
298      divlayer = document.layers[divname];
299        if(!divlayer){return;}
300      divlayer.document.open();
301      divlayer.document.write(msgstring);
302      divlayer.document.close();
303   }
304   else
305   if(document.all)
306   {
307      divlayer = document.all[divname];
308        if(!divlayer){return;}
309      divlayer.innerHTML=msgstring;
310   }
311   else
312   if(document.getElementById)
313   {
314      divlayer = document.getElementById(divname);
315        if(!divlayer){return;}
316      divlayer.innerHTML =msgstring;
317   }
318   divlayer.style.visibility="visible";   
319   return false;
320}
321function ValidationDesc(inputitem,desc,error,condition)
322{
323  this.desc=desc;
324   this.error=error;
325   this.itemobj = inputitem;
326   this.condition = condition;
327   this.validate=vdesc_validate;
328}
329function vdesc_validate()
330{
331   if(this.condition != null )
332   {
333      if(!eval(this.condition))
334      {
335         return true;
336      }
337   }
338   if(!validateInput(this.desc,this.itemobj,this.error))
339   {
340      this.itemobj.validatorobj.disable_validations=true;
341      this.itemobj.focus();
342      return false;
343   }
344   return true;
345}
346function ValidationSet(inputitem,msgs_together)
347{
348    this.vSet=new Array();
349   this.add= add_validationdesc;
350   this.validate= vset_validate;
351   this.itemobj = inputitem;
352    this.msgs_together = msgs_together;
353}
354function add_validationdesc(desc,error,condition)
355{
356  this.vSet[this.vSet.length]= 
357  new ValidationDesc(this.itemobj,desc,error,condition);
358}
359function vset_validate()
360{
361    var bRet = true;
362    for(var itr=0;itr<this.vSet.length;itr++)
363    {
364        bRet = bRet && this.vSet[itr].validate();
365        if(!bRet && !this.msgs_together)
366        {
367            break;
368        }
369    }
370    return bRet;
371}
372function validateEmail(email)
373{
374    var splitted = email.match("^(.+)@(.+)$");
375    if(splitted == null) return false;
376    if(splitted[1] != null )
377    {
378      var regexp_user=/^\"?[\w-_\.]*\"?$/;
379      if(splitted[1].match(regexp_user) == null) return false;
380    }
381    if(splitted[2] != null)
382    {
383      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
384      if(splitted[2].match(regexp_domain) == null) 
385      {
386       var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
387       if(splitted[2].match(regexp_ip) == null) return false;
388      }// if
389      return true;
390    }
391return false;
392}
393
394function IsCheckSelected(objValue,chkValue)
395{
396    var selected=false;
397   var objcheck = objValue.form.elements[objValue.name];
398    if(objcheck.length)
399   {
400      var idxchk=-1;
401      for(var c=0;c < objcheck.length;c++)
402      {
403         if(objcheck[c].value == chkValue)
404         {
405           idxchk=c;
406          break;
407         }//if
408      }//for
409      if(idxchk>= 0)
410      {
411        if(objcheck[idxchk].checked=="1")
412        {
413          selected=true;
414        }
415      }//if
416   }
417   else
418   {
419      if(objValue.checked == "1")
420      {
421         selected=true;
422      }//if
423   }//else  
424
425   return selected;
426}
427function TestDontSelectChk(objValue,chkValue,strError)
428{
429   var pass = true;
430   pass = IsCheckSelected(objValue,chkValue)?false:true;
431
432   if(pass==false)
433   {
434     if(!strError || strError.length ==0) 
435        { 
436         strError = "Can't Proceed as you selected "+objValue.name;  
437        }//if          
438     sfm_show_error_msg(strError,objValue);
439     
440   }
441    return pass;
442}
443function TestShouldSelectChk(objValue,chkValue,strError)
444{
445   var pass = true;
446
447   pass = IsCheckSelected(objValue,chkValue)?true:false;
448
449   if(pass==false)
450   {
451     if(!strError || strError.length ==0) 
452        { 
453         strError = "You should select"+objValue.name;  
454        }//if          
455     sfm_show_error_msg(strError,objValue);
456     
457   }
458    return pass;
459}
460function TestRequiredInput(objValue,strError)
461{
462 var ret = true;
463    if(eval(objValue.value.length) == 0) 
464    { 
465       if(!strError || strError.length ==0) 
466       { 
467         strError = objValue.name + " : Required Field"; 
468       }//if 
469       sfm_show_error_msg(strError,objValue); 
470       ret=false; 
471    }//if 
472return ret;
473}
474function TestMaxLen(objValue,strMaxLen,strError)
475{
476 var ret = true;
477    if(eval(objValue.value.length) > eval(strMaxLen)) 
478    { 
479      if(!strError || strError.length ==0) 
480      { 
481        strError = objValue.name + " : "+ strMaxLen +" characters maximum "; 
482      }//if 
483      sfm_show_error_msg(strError,objValue); 
484      ret = false; 
485    }//if 
486return ret;
487}
488function TestMinLen(objValue,strMinLen,strError)
489{
490 var ret = true;
491    if(eval(objValue.value.length) <  eval(strMinLen)) 
492    { 
493      if(!strError || strError.length ==0) 
494      { 
495        strError = objValue.name + " : " + strMinLen + " characters minimum  "; 
496      }//if               
497      sfm_show_error_msg(strError,objValue); 
498      ret = false;   
499    }//if 
500return ret;
501}
502function TestInputType(objValue,strRegExp,strError,strDefaultError)
503{
504   var ret = true;
505
506    var charpos = objValue.value.search(strRegExp); 
507    if(objValue.value.length > 0 &&  charpos >= 0) 
508    { 
509     if(!strError || strError.length ==0) 
510      { 
511        strError = strDefaultError;
512      }//if 
513      sfm_show_error_msg(strError,objValue); 
514      ret = false; 
515    }//if 
516 return ret;
517}
518function TestEmail(objValue,strError)
519{
520var ret = true;
521     if(objValue.value.length > 0 && !validateEmail(objValue.value)   ) 
522     { 
523       if(!strError || strError.length ==0) 
524       { 
525          strError = objValue.name+": Enter a valid Email address "; 
526       }//if                                               
527       sfm_show_error_msg(strError,objValue); 
528       ret = false; 
529     }//if 
530return ret;
531}
532function TestLessThan(objValue,strLessThan,strError)
533{
534var ret = true;
535     if(isNaN(objValue.value)) 
536     { 
537       sfm_show_error_msg(objValue.name +": Should be a number ",objValue); 
538       ret = false; 
539     }//if 
540     else
541     if(eval(objValue.value) >=  eval(strLessThan)) 
542     { 
543       if(!strError || strError.length ==0) 
544       { 
545         strError = objValue.name + " : value should be less than "+ strLessThan; 
546       }//if               
547       sfm_show_error_msg(strError,objValue); 
548       ret = false;                 
549      }//if   
550return ret;          
551}
552function TestGreaterThan(objValue,strGreaterThan,strError)
553{
554var ret = true;
555     if(isNaN(objValue.value)) 
556     { 
557       sfm_show_error_msg(objValue.name+": Should be a number ",objValue); 
558       ret = false; 
559     }//if 
560    else
561     if(eval(objValue.value) <=  eval(strGreaterThan)) 
562      { 
563        if(!strError || strError.length ==0) 
564        { 
565          strError = objValue.name + " : value should be greater than "+ strGreaterThan; 
566        }//if               
567        sfm_show_error_msg(strError,objValue);  
568        ret = false;
569      }//if  
570return ret;           
571}
572function TestRegExp(objValue,strRegExp,strError)
573{
574var ret = true;
575    if( objValue.value.length > 0 && 
576        !objValue.value.match(strRegExp) ) 
577    { 
578      if(!strError || strError.length ==0) 
579      { 
580        strError = objValue.name+": Invalid characters found "; 
581      }//if                                                               
582      sfm_show_error_msg(strError,objValue); 
583      ret = false;                   
584    }//if 
585return ret;
586}
587function TestDontSelect(objValue,dont_sel_value,strError)
588{
589var ret = true;
590     if(objValue.value == null) 
591     { 
592       sfm_show_error_msg("Error: dontselect command for non-select Item",objValue); 
593       ret = false; 
594     } 
595    else
596     if(objValue.value == dont_sel_value) 
597     { 
598      if(!strError || strError.length ==0) 
599       { 
600        strError = objValue.name+": Please Select one option "; 
601       }//if                                                               
602       sfm_show_error_msg(strError,objValue); 
603       ret =  false;                                   
604      } 
605return ret;
606}
607function TestSelectOneRadio(objValue,strError)
608{
609   var objradio = objValue.form.elements[objValue.name];
610   var one_selected=false;
611   for(var r=0;r < objradio.length;r++)
612   {
613     if(objradio[r].checked == "1")
614     {
615      one_selected=true;
616      break;
617     }
618   }
619   if(false == one_selected)
620   {
621      if(!strError || strError.length ==0) 
622       {
623       strError = "Please select one option from "+objValue.name;
624      }  
625     sfm_show_error_msg(strError,objValue);
626   }
627return one_selected;
628}
629
630function TestFileExtension(objValue,cmdvalue,strError)
631{
632    var ret=false;
633    var found=false;
634
635    if(objValue.value.length <= 0)
636    {//The 'required' validation is not done here
637        return true;
638    }
639   
640    var extns = cmdvalue.split(";");
641    for(var i=0;i < extns.length;i++)
642    {
643        ext = objValue.value.substr(objValue.value.length - extns[i].length,extns[i].length);
644        ext = ext.toLowerCase();
645        if(ext == extns[i])
646        {
647            found=true;break;
648        }
649    }
650    if(!found)
651    {
652       if(!strError || strError.length ==0) 
653       { 
654         strError = objValue.name + " allowed file extensions are: "+cmdvalue; 
655       }//if 
656       sfm_show_error_msg(strError,objValue); 
657       ret=false;        
658    }
659    else
660    {
661        ret=true;
662    }
663    return ret;
664}
665
666
667function validateInput(strValidateStr,objValue,strError) 
668{ 
669    var ret = true;
670    var epos = strValidateStr.search("="); 
671    var  command  = ""; 
672    var  cmdvalue = ""; 
673    if(epos >= 0) 
674    { 
675     command  = strValidateStr.substring(0,epos); 
676     cmdvalue = strValidateStr.substr(epos+1); 
677    } 
678    else 
679    { 
680     command = strValidateStr; 
681    } 
682    switch(command) 
683    { 
684        case "req": 
685        case "required": 
686         { 
687         ret = TestRequiredInput(objValue,strError)
688           break;             
689         }//case required 
690        case "maxlength": 
691        case "maxlen": 
692          { 
693          ret = TestMaxLen(objValue,cmdvalue,strError)
694             break; 
695          }//case maxlen 
696        case "minlength": 
697        case "minlen": 
698           { 
699          ret = TestMinLen(objValue,cmdvalue,strError)
700             break; 
701            }//case minlen 
702        case "alnum": 
703        case "alphanumeric": 
704           { 
705            ret = TestInputType(objValue,"[^A-Za-z0-9]",strError, 
706                  objValue.name+": Only alpha-numeric characters allowed ");
707            break; 
708           }
709        case "alnum_s": 
710        case "alphanumeric_space": 
711           { 
712            ret = TestInputType(objValue,"[^A-Za-z0-9\\s]",strError, 
713                  objValue.name+": Only alpha-numeric characters and space allowed ");
714            break; 
715           }         
716        case "num": 
717        case "numeric": 
718           { 
719                ret = TestInputType(objValue,"[^0-9]",strError, 
720                  objValue.name+": Only digits allowed ");
721                break;               
722           }
723        case "alphabetic": 
724        case "alpha": 
725           { 
726                ret = TestInputType(objValue,"[^A-Za-z]",strError, 
727                  objValue.name+": Only alphabetic characters allowed ");
728                break; 
729           }
730        case "alphabetic_space": 
731        case "alpha_s": 
732           { 
733                ret = TestInputType(objValue,"[^A-Za-z\\s]",strError, 
734                  objValue.name+": Only alphabetic characters and space allowed ");
735                break; 
736           }
737        case "email": 
738          { 
739            ret = TestEmail(objValue,strError);
740               break; 
741          }
742        case "lt": 
743        case "lessthan": 
744         { 
745            ret = TestLessThan(objValue,cmdvalue,strError);
746              break; 
747         }
748        case "gt": 
749        case "greaterthan": 
750         { 
751         ret = TestGreaterThan(objValue,cmdvalue,strError);
752            break; 
753         }//case greaterthan 
754        case "regexp": 
755         { 
756         ret = TestRegExp(objValue,cmdvalue,strError);
757           break; 
758         }
759        case "dontselect": 
760         { 
761          ret = TestDontSelect(objValue,cmdvalue,strError)
762             break; 
763         }
764      case "dontselectchk":
765      {
766         ret = TestDontSelectChk(objValue,cmdvalue,strError)
767         break;
768      }
769      case "shouldselchk":
770      {
771         ret = TestShouldSelectChk(objValue,cmdvalue,strError)
772         break;
773      }
774      case "selone_radio":
775      {
776         ret = TestSelectOneRadio(objValue,strError);
777          break;
778      }
779      case "file_extn":
780      {
781         ret = TestFileExtension(objValue,cmdvalue,strError);
782         break;
783      }      
784    }//switch 
785   return ret;
786}
787function VWZ_IsListItemSelected(listname,value)
788{
789 for(var i=0;i < listname.options.length;i++)
790 {
791  if(listname.options[i].selected == true &&
792   listname.options[i].value == value) 
793   {
794     return true;
795   }
796 }
797 return false;
798}
799function VWZ_IsChecked(objcheck,value)
800{
801 if(objcheck.length)
802 {
803     for(var c=0;c < objcheck.length;c++)
804     {
805       if(objcheck[c].checked == "1" && 
806        objcheck[c].value == value)
807       {
808        return true; 
809       }
810     }
811 }
812 else
813 {
814  if(objcheck.checked == "1" )
815   {
816    return true; 
817   }    
818 }
819 return false;
820}
821/*
822   Copyright (C) 2003-2008 JavaScript-Coder.com . All rights reserved.
823*/

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.