PageSourceSearch

https://charlottesny.com//jscripts/validation.js

js charlottesny.com collected 2026-10-08 16:17:35 UTC 34,804 bytes, 1,274 lines download raw bytes

1    /*  Validation functions starts here..... */
2
3    //returns value of a radio button that is checked
4	function RadioValue(objForm,strName)
5	{
6        var val;
7		for(i=0; i<objForm.elements.length; i++)
8		{
9			var name=objForm.elements[i].name;
10			var type=objForm.elements[i].type;
11			if((type=="radio") && (name.indexOf(strName)!=-1))
12			{
13                if (objForm.elements[i].checked){
14					val = objForm.elements[i].value;
15				}
16			}
17		}
18		return val;
19	}
20
21    function invalidemail(y)
22    {
23
24        var len = y.length;
25        if (len < 1)
26        {
27            return true;
28        }
29        var i = 0;
30        for (i=0; i<len; i++)
31        {
32            if (!((y.charCodeAt(i) >= 65 && y.charCodeAt(i) <= 90)
33              || (y.charCodeAt(i) >= 97 && y.charCodeAt(i) <= 122)
34              || (y.charCodeAt(i) >= 48 && y.charCodeAt(i) <= 57)
35              || (y.charAt(i) == "@")
36              || (y.charAt(i) == "_")
37              || (y.charAt(i) == "-")
38              || (y.charAt(i) == ".")))
39            {
40                return true;
41            }
42        }
43        var at = y.indexOf("@");
44        if (at < 0)
45        {
46            return true;
47        }
48        i = 0;
49        var dot;
50        dot = y.indexOf(".", at);
51        if (!(dot > 1))
52        {
53            return true;
54        }
55        return false;
56    }
57
58    function isValidURL(strText)
59    {
60        var bcorrect=true;
61        if(bcorrect && isNull(strText))
62        {
63            return true;
64        }
65        if(bcorrect && strText.indexOf("/")!=-1)
66        {
67            strText=strText.substring(0,strText.indexOf("/"));
68        }
69
70        var len = strText.length;
71
72        //validate the characters allowed
73        if(bcorrect)
74        {
75            var i = 0;
76            for (i=0; i<len; i++)
77            {
78                if (!((strText.charCodeAt(i) >= 65 && strText.charCodeAt(i) <= 90)
79                  || (strText.charCodeAt(i) >= 97 && strText.charCodeAt(i) <= 122)
80                  || (strText.charCodeAt(i) >= 48 && strText.charCodeAt(i) <= 57)
81                  || (strText.charAt(i) == "-")
82                  || (strText.charAt(i) == "_")
83                  || (strText.charAt(i) == ".")))
84                {
85                    bcorrect=false;
86                }
87            }
88        }
89
90        if(bcorrect && strText.indexOf("..")!=-1)
91            bcorrect=false;
92        if(bcorrect && strText.indexOf("-")==0)
93            bcorrect=false;
94        if(bcorrect && strText.indexOf("_")==0)
95            bcorrect=false;
96        if(bcorrect && strText.indexOf(".")==0)
97            bcorrect=false;
98        if(bcorrect && strText.indexOf(".")==-1)
99            bcorrect=false;
100
101        //validate last index of '.' and number of chars next to that
102        if(bcorrect)
103        {
104            var iLastPos=strText.lastIndexOf('.');
105            var iMasphar=len - iLastPos;
106            if(iMasphar<3 || iMasphar>5)
107                bcorrect=false;
108        }
109
110        //validate extension
111        if(bcorrect)
112        {
113            var strExtension=strText.substring(strText.lastIndexOf('.')+1);
114            if(!isAlphaNumeric(strExtension))
115                bcorrect=false;
116        }
117        return bcorrect;
118    }
119
120    function isNotNumeric(n)
121    {
122        if (n == "")
123        {
124            return true;
125        }
126        var len = n.length;
127        var i = 0;
128        for (i=0; i<len; i++)
129        {
130            if (!((n.charCodeAt(i) >= 48) && (n.charCodeAt(i) <= 57)))
131            {
132                return true;
133            }
134        }
135        return false;
136    }
137
138    function containsBlank(s)
139    {
140        var len = s.length;
141        for (i=0; i<len; i++)
142        {
143            if (s.charAt(i) == " ")
144            {
145                return true;
146            }
147        }
148        return false;
149    }
150
151    function isBlank(StrText)
152    {
153        if (StrText.length < 0)
154        {
155            return true;
156        }
157        for (var i=0; i<StrText.length; i++)
158        {
159            if (StrText.charAt(i) != " ")
160            {
161                return false;
162            }
163        }
164        return true;
165    }
166
167    function getSelectedOption(OItem)
168    {
169        var optionValue = "";
170        for (var i=0; i<OItem.length; i++)
171        {
172            if (OItem.options[i].selected == true)
173            {
174                 optionValue = OItem.options[i].value;
175                 return optionValue;
176            }
177        }
178    }
179
180    function optionSelected(OItem)
181    {
182        for (var i=0; i<OItem.length; i++)
183        {
184            if ((OItem.options[i].selected == true) && (OItem.options[i].value != ""))
185            {
186                return true;
187            }
188        }
189        return false;
190    }
191
192    function isValidDate(iYear, iMonth, iDay)
193    {
194        if (isNaN(iYear) || isNaN(iMonth) || isNaN(iDay))
195        {
196          return false;
197        }
198            var dtNewDate = new Date(iYear, (iMonth-1), iDay);
199            if ((parseInt(dtNewDate.getFullYear()) == iYear)
200                && (parseInt(dtNewDate.getMonth()) == (iMonth-1))
201                && (parseInt(dtNewDate.getDate()) == iDay))
202            {
203                return true;
204            }
205        return false;
206    }
207
208    //Returns true if "text" is alphanumeric
209    function isAlphaNumeric(text)
210    {
211        var str = new String(text);
212        for (var i=0;i<str.length;i++)
213        {
214            if (!((str.charCodeAt(i)>=65 && str.charCodeAt(i)<=90) || (str.charCodeAt(i)>=97 && str.charCodeAt(i)<=122) || (str.charCodeAt(i)>=48 && str.charCodeAt(i)<=57)))
215            {
216                return false;
217            }
218         }
219        return true;
220    }
221
222    // returns true if the given text is Null
223    function isNull(text)
224    {
225        if((trim(text) == "") || (text == null))
226        {
227            //alert("Must not be Null Sring");
228            return true;
229        }
230        else
231        {
232            return false;
233        }
234    }
235
236    // returns true if length of the text is greater than given num.
237    function isMaxLength(text,num)
238    {
239        var strlen;
240        var text=new String(text);
241        strlen = len(text);
242        if (strlen > num)
243        {
244            //alert(" Must not be greater than maximum " + num + " characters ");
245            return true;
246        }
247        else
248        {
249            return false;
250        }
251    }
252
253    // returns true if length of the text is less than given value.
254     function isMinLength(text,num)
255    {
256        var strlen;
257        var text=new String(text);
258        strlen = len(text);
259        if (strlen < num)
260        {
261            //alert(" Must not be Less than minimum " + num + " characters ");
262            return true;
263        }
264        else
265        {
266            return false;
267        }
268    }
269
270    // returns true if the text is Number and false if it is not a number.
271    function isNumber(text)
272    {
273        var ilen;
274        var bflagNum=true;
275        var text=new String(text);
276        if (isNaN(text))
277        {
278            return false;
279        }
280        else
281        {
282            return true;
283        }
284    }
285
286    // returns true if valid Email.
287    function isEmail(emailval)
288    {
289        var tempStr,icount;
290        var blnmail,blnperiod;
291        var lastoccofperiod,maxthree;
292        var ampicount=0;
293        var amppos;
294        var servername = 1;
295        var dots;
296        icount=emailval.length;
297        blnperiod = 1;
298        maxthree = 1;
299        specialchar = 0
300        lastoccofperiod = 0;
301        if (icount==0)
302        {
303            return true;
304        }
305        for(i=0;i<icount;i++)
306        {
307            tempStr = emailval.charAt(i);
308            if ((tempStr >='a')&&(tempStr <='z'))
309            {
310                specialchar=specialchar+1;
311            }
312            else
313            {
314                if ((tempStr >='A')&&(tempStr <='Z'))
315                {
316                    specialchar=specialchar+1;
317                }
318                else
319                {
320                    if ((tempStr >= 0)&&(tempStr<=9))
321                    {
322                        specialchar=specialchar+1;
323                    }
324                    else
325                    {
326                        if ((tempStr=='_')||(tempStr=='-')||(tempStr=='.')||(tempStr=='@'))
327                        {
328                            specialchar=specialchar+1;
329                        }
330                        else
331                        {
332                            return false;
333                        }
334                    }
335                }
336            }
337        }
338        dots = emailval.indexOf('..');
339        if (dots != -1)
340        {
341            return false;
342        }
343        espace = emailval.indexOf(' ');
344        if (espace != -1)
345        {
346            return false;
347        }
348        lastoccofperiod = emailval.lastIndexOf('.');
349        if (lastoccofperiod <= 0)
350        {
351            blnperiod = 0;
352        }
353        if (((icount - lastoccofperiod) > 4)||((icount - lastoccofperiod) < 3))
354        {
355            maxthree = 0;
356        }
357         for(i=0;i<=icount;i++)
358        {
359            tempStr = emailval.charAt(i)
360            if (tempStr=='@')
361            ampicount=ampicount + 1;
362        }
363        amppos = emailval.indexOf('@');
364        if (emailval.charAt(amppos+1) == '.')
365        servername = 0;
366        if(icount - emailval.charAt(amppos)< 5)
367        servername = 0;
368        if ((ampicount==1)&&(blnperiod==1)&&(maxthree==1)&&(servername==1))
369        {
370            blnmail=1;
371        }
372        else
373        {
374             blnmail=0;
375        }
376         //return blnmail;
377        if (blnmail==0)
378        {
379            //alert('Please enter a valid email address');
380            return false;
381        }
382        else
383        {
384            return true;
385        }
386     }
387
388    //returns true if the text carries only alphabets.
389    function isAlphabetic(textval)
390    {
391        var text=new String(textval);
392        var ilen;
393        var bflag=true;
394        for(ilen=0;ilen<=text.length;ilen++)
395        {
396            if(text.charCodeAt(ilen) < 65 || text.charCodeAt(ilen) > 90 && text.charCodeAt(ilen) < 97 || text.charCodeAt(ilen) > 122)
397            {
398                bflag=false;
399            }
400        }
401        return bflag;
402    }
403
404    function isCurrency(text)
405    {
406        var bflag=true;
407        if(text != "")
408        {
409            var k = len(text);
410            var i;
411            for (i=0; i<k; i++)
412            {
413                if (!((text.charCodeAt(i) >= 48 && text.charCodeAt(i) <= 57) || (text.charAt(i) == ".")))
414                {
415                    bflag=false;
416                }
417            }
418        }
419        return bflag;
420    }
421    //isTelephoneNumber -returns true if it is valid Telephone or Fax Number.allowing +-.()
422    function isTelephoneNumber(text)
423    {
424        var bflag=true;
425        if(text != "")
426        {
427            var k = len(text);
428            var i;
429            for (i=0; i<k; i++)
430            {
431                if (!((text.charCodeAt(i) >= 48 && text.charCodeAt(i) <= 57) || (text.charAt(i) == "-")|| (text.charAt(i) == "(")|| (text.charAt(i) == ")") || (text.charAt(i) == "+") || (text.charAt(i) == ".")|| (text.charAt(i) == " ")))
432                {
433                    bflag=false;
434                }
435            }
436        }
437        return bflag;
438    }
439
440    //returns true if it is valid date.
441    function isDate(date,month,year)
442    {
443        var bflag=true;
444        if (isNaN(year) || isNaN(month) || isNaN(date))
445        {
446            bflag=false;
447        }
448        if(bflag)
449        {
450            var dtnew = new Date(year,month-1,date);
451            if ((parseInt(dtnew.getFullYear()) == year) && (parseInt(dtnew.getMonth()) == (month-1)) && (parseInt(dtnew.getDate()) == date))
452            {
453                bflag=true;
454            }
455            else
456            {
457                bflag=false;
458            }
459        }
460        return bflag;
461    }
462
463    //returns string by removing whitespaces from both the ends.
464    function trim(text)
465    {
466        var stext = new String(text);
467        var sresult = "";
468        //Remove leading spaces
469        for (var i=0; i<stext.length; i++)
470        {
471            if (stext.charAt(i) != " ")
472            {
473                sresult = stext.substr(i, (stext.length - i));
474                break;
475            }
476        }
477        stext = sresult;
478        //Remove trailing spaces
479        for (var j=(stext.length - 1); j>=0; j--)
480        {
481            if (stext.charAt(j) != " ")
482            {
483                sresult = stext.substr(0, (j + 1));
484                break;
485            }
486        }
487        return sresult;
488    }
489
490    // returns length of the text
491    function len(text)
492    {
493        var strText=new String(text);
494        return strText.length;
495    }
496
497    // selecting & focusing on the element that holds asporrect value
498    function selectFocus(element)
499    {
500        element.select();
501        element.focus();
502        return true;
503    }
504
505    //returns true if a radio button is checked
506    function IsRadioChecked(objForm,strName)
507    {
508        var bcorrect;
509        bcorrect=false;
510        for(i=0; i<objForm.elements.length; i++)
511        {
512            var name=objForm.elements[i].name;
513            var type=objForm.elements[i].type;
514            if((type=="radio") && (name.indexOf(strName)!=-1))
515            {
516                var val=objForm.elements[i].checked;
517                if(val==true)
518                {
519                    bcorrect=true;
520                    break;
521                }
522            }
523        }
524        return bcorrect;
525    }
526
527    //returns true if atleast one check box is selected
528    function IsCheckboxSelected(objForm,strName)
529    {
530        var bcorrect=false;
531        for(var i=0; i<objForm.elements.length; i++)
532        {
533            var name=objForm.elements[i].name;
534            var type=objForm.elements[i].type;
535            if((type=="checkbox") && (name.indexOf(strName)!=-1))
536            {
537                var val=objForm.elements[i].checked;
538                if(val==true)
539                {
540                    bcorrect = true;
541                    break;
542                }
543            }
544        }
545        return bcorrect;
546    }
547
548    /*  Validation functions ends here. */
549
550
551    /*  HTML Element Validation functions starts here..... */
552    //HTML Element "Text box" validations (includes text area also.)
553    function ValidateTextBox(strName,obj,bZeroLength,iMaxChars,bAlphabet,bNumeric,bAlphanumeric,bEmail,bTelNumber,bURL,bFile,strFileType,bCurrency)
554    {
555        var bCorrect=true;
556
557        //Zerolength validation is optional, if bZeroLength is true then textbox value is checked for zerolength.
558        if(bCorrect && bZeroLength)
559        {
560            if(isNull(obj.value))
561            {
562                bCorrect=false;
563                alert(strName + " is blank.");
564                selectFocus(obj);
565            }
566        }
567
568        //MaxLength is not optional
569        if(bCorrect)
570        {
571            if(isMaxLength(obj.value,iMaxChars))
572            {
573                bCorrect=false;
574                alert(strName + " is greater than " + iMaxChars + " characters.");
575                selectFocus(obj);
576            }
577        }
578
579        //Alphabet validation is optional, if bAlphabet is true then textbox value is checked for Alphabets.
580        if(bCorrect && bAlphabet)
581        {
582            if(!isAlphabetic(obj.value))
583            {
584                bCorrect=false;
585                alert(strName + " must have only alphabets.");
586                selectFocus(obj);
587            }
588        }
589
590        //Numeric validation is optional, if bNumeric is true then textbox value is checked for Numeric.
591        if(bCorrect && bNumeric)
592        {
593            if(!isNumber(obj.value))
594            {
595                bCorrect=false;
596                alert(strName + " must have only numbers.");
597                selectFocus(obj);
598            }
599        }
600
601        //Alphanumeric validation is optional, if bAlphanumeric is true then textbox value is checked for Alphanumeric.
602        if(bCorrect && bAlphanumeric)
603        {
604            if(!isAlphaNumeric(obj.value))
605            {
606                bCorrect=false;
607                alert(strName + " must have only alphanumeric characters.");
608                selectFocus(obj);
609            }
610        }
611
612        //Email validation is optional, if bEmail is true then textbox value is checked for Email.
613        if(bCorrect && bEmail)
614        {
615            if(!isEmail(obj.value))
616            {
617                bCorrect=false;
618                alert(strName + " entered is not a valid email address.");
619                selectFocus(obj);
620            }
621        }
622
623        //TelNumber validation is optional, if bTelNumber is true then textbox value is checked for TelNumber.
624        if(bCorrect && bTelNumber)
625        {
626            if(!isTelephoneNumber(obj.value))
627            {
628                bCorrect=false;
629                alert(strName + " is not a valid telephone/fax number.");
630                selectFocus(obj);
631            }
632        }
633
634        //URL validation is optional, if bURL is true then textbox value is checked for URL.
635        if(bCorrect && bURL)
636        {
637            if(!isValidURL(obj.value))
638            {
639                bCorrect=false;
640                alert(strName + " is not a valid URL.");
641                selectFocus(obj);
642            }
643        }
644        if(bCorrect && bFile)
645        {
646            if(!isFile(obj.value,strFileType))
647            {
648                bCorrect=false;
649                alert(strName + " is not a valid File Type.");
650                selectFocus(obj);
651            }
652        }
653        if(bCorrect && bCurrency)
654        {
655            if(!isCurrency(obj.value))
656            {
657                bCorrect=false;
658                alert(strName + " is not a valid number.");
659                selectFocus(obj);
660            }
661        }
662        return bCorrect;
663    }
664
665
666    //HTML Element "Drop-down list" validations
667    function ValidateDropdownList(strName,obj,bSelect,iMaxChars)
668    {
669        var bCorrect=true;
670
671        //Select validation is optional, if bSelect is true then textbox value is checked for Selection.
672        if(bCorrect && bSelect)
673        {
674            if(getSelectedOption(obj)=="")
675            {
676                bCorrect=false;
677                alert(strName + " is not selected.");
678                obj.focus();
679            }
680        }
681
682        //MaxLength is not optional
683        if(bCorrect)
684        {
685            if(isMaxLength(getSelectedOption(obj),iMaxChars))
686            {
687                bCorrect=false;
688                alert(strName + " is greater than " + iMaxChars + " characters.");
689                obj.focus();
690            }
691        }
692
693        return bCorrect;
694    }
695
696    //HTML Element "Radio button" validations
697    function ValidateRadioButton(strLabel,strRadioName,objForm,bChecked)
698    {
699        var bCorrect=true;
700
701        //Radio button validation is optional, if bChecked is true then it is checked for Selection.
702        if(bCorrect && bChecked)
703        {
704            if(!IsRadioChecked(objForm,strRadioName))
705            {
706                bCorrect=false;
707                alert(strLabel + " is not selected.");
708            }
709        }
710        return bCorrect;
711    }
712
713    //HTML Element "Check box" validations
714    function ValidateCheckBox(strLabel,strCheckBoxName,objForm,bChecked)
715    {
716        var bCorrect=true;
717
718        //Check box validation is optional, if bChecked is true then it is checked for Selection.
719        if(bCorrect && bChecked)
720        {
721            if(!IsCheckboxSelected(objForm,strCheckBoxName))
722            {
723                bCorrect=false;
724                alert(strLabel + " is not selected.");
725            }
726        }
727        return bCorrect;
728    }
729
730    // validate date box.
731    function ValidateDateBox(strLabel,obj,iDay,iMonth,iYear,bSelected,bFutureDate,bPastDate)
732    {
733        var bcorrect=true;
734        if(bSelected)
735        {
736            if(bcorrect && !isDate(iDay,iMonth,iYear))
737            {
738                bcorrect=false;
739                alert("Please select a valid " + strLabel + ".");
740                obj.focus();
741            }
742        }
743        if(iDay!="" && iMonth!="" && iYear!="")
744        {
745            if(bcorrect && !isDate(iDay,iMonth,iYear))
746            {
747                bcorrect=false;
748                alert("Please select a valid " + strLabel + ".");
749                obj.focus();
750            }
751        }
752        if (bFutureDate)
753        {
754            if(bcorrect)
755            {
756                var dtnew = new Date(iYear,iMonth-1,iDay);
757                var dtnow = new Date();
758                if(dtnew<dtnow)
759                {
760                    bcorrect=false;
761                    alert("Please select a valid future date.");
762                    obj.focus();
763                }
764            }
765        }
766        if(bPastDate)
767        {
768            if(bcorrect)
769            {
770                var dtnew = new Date(iYear,iMonth-1,iDay);
771                var dtnow = new Date();
772                if(dtnew>dtnow)
773                {
774                    bcorrect=false;
775                    alert("Please select a valid past date.");
776                    obj.focus();
777                }
778            }
779        }
780        return bcorrect;
781    }
782
783
784    //select All checkboxes starting with..
785    function SelectAllCheckBoxes(strFormName,strSearchChars,strSelectAll)
786    {
787        var objForm=eval("document." + strFormName);
788        for(var i=0; i<objForm.length; i++)
789        {
790            if(objForm.elements[i].type == "checkbox")
791            {
792                var strCheckBoxName = new String(objForm.elements[i].name);
793                if(strCheckBoxName.indexOf(strSearchChars) != -1)
794                {
795                    var objCheckBox = eval("document." + strFormName + "." + strCheckBoxName);
796                    if(eval("document." + strFormName + "." + strSelectAll + ".checked")==true)
797                        objCheckBox.checked  = true;
798                    else
799                        objCheckBox.checked = false;
800                }
801            }
802        }
803    }
804
805    //unselect the checkbox named "ALL" when any one of the other checkboxe(s) unselected.
806    function UnSelectCheckBox(strFormName,strSearchChars,strSelectAll)
807    {
808        var bcheckbox=true;
809        var objForm=eval("document." + strFormName);
810        for(var i=0; i<objForm.length; i++)
811        {
812            if(objForm.elements[i].type == "checkbox")
813            {
814                var strCheckBoxName = new String(objForm.elements[i].name);
815                if(strCheckBoxName.indexOf(strSearchChars) != -1)
816                {
817                    var objCheckBox = eval("document." + strFormName + "." + strCheckBoxName);
818                    if(objCheckBox.checked==false)
819                        bcheckbox=false;
820                }
821            }
822        }
823        var objCheckBoxAll=eval("document." + strFormName + "." + strSelectAll);
824        if (objCheckBoxAll != null)
825        {
826            if(bcheckbox)
827                objCheckBoxAll.checked=true;
828            else
829                objCheckBoxAll.checked=false;
830        }
831    }
832
833    //selected checkbox values are stored in the hidden field with "," as delimiter
834    function StoreSelectedCheckBoxes(strFormName,strHiddenName,strSearchChars)
835    {
836        var objForm=eval("document." + strFormName);
837        var objHidden=eval("document." + strFormName + "." + strHiddenName);
838        var iLen=strSearchChars.length;
839        eval("document." + strFormName + "." + strHiddenName).value="";
840        for(var iLoop=0;iLoop<objForm.elements.length;iLoop++)
841        {
842            if(objForm.elements[iLoop].type=="checkbox")
843            {
844                var strCheckBoxName=new String(objForm.elements[iLoop].name);
845                if(strCheckBoxName.slice(0,iLen)==strSearchChars)
846                {
847                    if(objForm.elements[iLoop].checked==true)
848                    {
849                        objHidden.value+=(objHidden.value=="") ? strCheckBoxName.slice(iLen) : ("," + strCheckBoxName.slice(iLen));
850                    }
851                }
852            }
853        }
854        //alert(objHidden.value);
855    }
856
857    //Checks whether file type is ends with specified extension or not
858
859    function isFile(strValue,strFileType)
860    {
861        var bCorrect=false;
862        strImage=new String(strValue);
863        var bHtml=false;
864        var bAll=false;
865        var bImage=false;
866        if(strValue.length==0)
867        {
868            return true;
869        }
870        if(strFileType.toLowerCase()=="htm" || strFileType.toLowerCase()=="html")
871        {
872            bHtml=true;
873        }
874        if(strFileType.toLowerCase()=="all")
875        {
876            bAll=true;
877        }
878        if(strFileType.toLowerCase()=="img")
879        {
880            bImage=true;
881        }
882        if(strImage.indexOf(".")!=-1)
883        {
884            iIndex=strImage.indexOf(".");
885            if(bAll==true)
886            {
887                strFile=strImage.substring(iIndex+1);
888                if(strFile.length>=2)
889                {
890                    bCorrect=true;
891                    return bCorrect;
892
893                }
894                else
895                {
896                    bCorrect=false;
897                    return bCorrect;
898
899                }
900            }
901            else    if(bImage==true)
902            {
903                if((strImage.substring(iIndex+1)).toLowerCase()=="gif" || (strImage.substring(iIndex+1)).toLowerCase()=="jpg" || (strImage.substring(iIndex+1)).toLowerCase()=="jpeg" || (strImage.substring(iIndex+1)).toLowerCase()=="bmp")
904                {
905                    bCorrect=true;
906                    return bCorrect;
907
908                }
909                else
910                {
911                    bCorrect=false;
912                    return bCorrect;
913
914                }
915            }
916            else    if(bHtml==true)
917            {
918                if((strImage.substring(iIndex+1)).toLowerCase()=="htm" || (strImage.substring(iIndex+1)).toLowerCase()=="html")
919                {
920                    bCorrect=true;
921                    return bCorrect;
922
923                }
924                else
925                {
926                    bCorrect=false;
927                    return bCorrect;
928
929                }
930            }
931            else
932            {
933                if((strImage.substring(iIndex+1)).toLowerCase()==strFileType.toLowerCase())
934                {
935                    bCorrect=true;
936                    return bCorrect;
937
938                }
939                else
940                {
941                    bCorrect=false;
942                    return bCorrect;
943
944                }
945            }
946        }
947        else
948        {
949            bCorrect=false;
950            return bCorrect;
951        }
952    }
953    /*  HTML Element Validation functions ends here. */
954
955
956function isValidCreditCard(strValue)
957{
958    var b_correct = true;
959    if(b_correct)
960    {
961        if(isNotNumeric(strValue))
962        {
963            b_correct = false;
964        }
965    }
966    if(b_correct)
967    {
968        var str_len=strValue.length;
969        var b=0;
970        var a=1;
971        for(var i=str_len;i>=1;i--)
972        {
973            if(a%2!=0)
974            {
975                b=b+parseInt(strValue.substring(i-1,i));
976            }
977            else
978            {
979                var j;
980                j=strValue.substring(i-1,i)*2;
981                if(j.toString().length>1)
982                {
983                    for(var s=0;s<=1;s++)
984                    {
985                        b=b+parseInt((j.toString()).substring(s,s+1));
986                    }
987                }
988                else
989                {
990                    b=b+j;
991                }
992            }
993            a=a+1;
994        }
995        if(b%10==0)
996        {
997            b_correct=true;
998        }
999        else
1000        {
1001            b_correct=false;
1002        }
1003    }
1004    return b_correct;
1005}
1006
1007
1008//************** DD/MM/YYYY DATE VALIDATION STARTS HERE *******************************//
1009var dtCh= "/";
1010var minYear=1900;
1011var maxYear=2100;
1012
1013function isInteger(s)
1014{
1015    var i;
1016    for (i = 0; i < s.length; i++)
1017        {
1018        // Check that current character is number.
1019        var c = s.charAt(i);
1020        if (((c < "0") || (c > "9"))) return false;
1021    }
1022    // All characters are numbers.
1023    return true;
1024}
1025
1026function stripCharsInBag(s, bag)
1027{
1028    var i;
1029    var returnString = "";
1030    // Search through string's characters one by one.
1031    // If character is not in bag, append to returnString.
1032    for (i = 0; i < s.length; i++)
1033        {
1034        var c = s.charAt(i);
1035        if (bag.indexOf(c) == -1) returnString += c;
1036    }
1037    return returnString;
1038}
1039
1040function daysInFebruary (year)
1041{
1042    // February has 29 days in any year evenly divisible by four,
1043    // EXCEPT for centurial years which are not also divisible by 400.
1044    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
1045}
1046function DaysArray(n)
1047{
1048    for (var i = 1; i <= n; i++)
1049    {
1050        this[i] = 31
1051        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
1052        if (i==2) {this[i] = 29}
1053   }
1054   return this
1055}
1056
1057function is_ddmmyyyy(dtStr)
1058{
1059    var daysInMonth = DaysArray(12)
1060    var pos1=dtStr.indexOf(dtCh)
1061    var pos2=dtStr.indexOf(dtCh,pos1+1)
1062    var strDay=dtStr.substring(0,pos1)
1063    var strMonth=dtStr.substring(pos1+1,pos2)
1064    var strYear=dtStr.substring(pos2+1)
1065    strYr=strYear
1066    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
1067    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
1068    for (var i = 1; i <= 3; i++) {
1069        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
1070    }
1071    month=parseInt(strMonth)
1072    day=parseInt(strDay)
1073    year=parseInt(strYr)
1074    if (pos1==-1 || pos2==-1)
1075    {
1076        alert("The date format should be : dd/mm/yyyy")
1077        return false
1078    }
1079    if (strMonth.length<1 || month<1 || month>12)
1080    {
1081        alert("Please enter a valid month")
1082        return false
1083    }
1084    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
1085    {
1086        alert("Please enter a valid day")
1087        return false
1088    }
1089    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
1090    {
1091        alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
1092        return false
1093    }
1094    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
1095    {
1096        alert("Please enter a valid date")
1097        return false
1098    }
1099    return true
1100}
1101
1102 //************** DD/MM/YYYY DATE VALIDATION  ENDS HERE********************************//
1103
1104
1105
1106//************** HH:MM:SS AM/PM format VALIDATION STARTS HERE********************************//
1107    function IsValidTime(timeStr)
1108    {
1109        // Checks if time is in HH:MM:SS AM/PM format.
1110        // The seconds and AM/PM are optional.
1111        var b_correct=true;
1112
1113        if(!isNull(timeStr))
1114        {
1115            var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
1116
1117            var matchArray = timeStr.match(timePat);
1118            if (b_correct && matchArray == null)
1119            {
1120                alert("Time is not in a valid format.");
1121                b_correct = false;
1122            }
1123
1124            if(b_correct)
1125            {
1126                hour = matchArray[1];
1127                minute = matchArray[2];
1128                second = matchArray[4];
1129                ampm = matchArray[6];
1130
1131                if (second=="") { second = null; }
1132                if (ampm=="") { ampm = null }
1133            }
1134
1135            if (b_correct && hour < 0  || hour > 23)
1136            {
1137                alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
1138                b_correct = false;
1139            }
1140            if (b_correct && hour <= 12 && ampm == null)
1141            {
1142                //if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time"))
1143                //{
1144                    alert("You must specify AM or PM.");
1145                    b_correct = false;
1146               //}
1147            }
1148            if  (b_correct && hour > 12 && ampm != null)
1149            {
1150                alert("You can't specify AM or PM for military time.");
1151                b_correct = false;
1152            }
1153            if (b_correct && minute<0 || minute > 59)
1154            {
1155                alert ("Minute must be between 0 and 59.");
1156                b_correct = false;
1157            }
1158            if (b_correct && second != null && (second < 0 || second > 59))
1159            {
1160                alert ("Second must be between 0 and 59.");
1161                b_correct = false;
1162            }
1163        }
1164
1165        return b_correct;
1166    }
1167//************** HH:MM:SS AM/PM format VALIDATION ENDS HERE********************************//
1168
1169function getLength(str)
1170{
1171    while (str.substr(str.length-1)==" ")
1172    {
1173        str = str.substring(0,str.length-1);
1174    }
1175    return str.length
1176}
1177function isValidDateshort(iYear, iMonth, iDay)
1178{
1179    if (isNaN(iYear) || isNaN(iMonth) || isNaN(iDay))
1180    {
1181      return false;
1182    }
1183
1184        var dtNewDate = new Date(iYear, (iMonth-1), iDay);
1185        if ((parseInt(dtNewDate.getYear()) == iYear)
1186            && (parseInt(dtNewDate.getMonth()) == (iMonth-1))
1187            && (parseInt(dtNewDate.getDate()) == iDay))
1188        {
1189            return true;
1190        }
1191    return false;
1192}
1193function timevalidateshort(curtime)
1194{
1195    bcorrect = 1;
1196    if (getLength(curtime)!=5)
1197    {
1198        bcorrect = 0;
1199    }
1200    if (curtime.slice(2,3)!=":")
1201    {
1202        bcorrect = 0;
1203    }
1204    if(isNumber(curtime.slice(0,2)))
1205    {
1206        if((curtime.slice(0,2)<0) || (curtime.slice(0,2)>23))
1207        {
1208            bcorrect = 0;
1209        }
1210    }else{
1211        bcorrect = 0;
1212    }
1213    if(isNumber(curtime.slice(3,5)))
1214    {
1215        if((curtime.slice(3,5)<0) || (curtime.slice(3,5)>59))
1216        {
1217            bcorrect = 0;
1218        }
1219    }else{
1220        bcorrect = 0;
1221    }
1222
1223    return bcorrect;
1224}
1225
1226function timevalidatelong(curtime)
1227{
1228    bcorrect = 1;
1229    if (getLength(curtime)!=8)
1230    {
1231        bcorrect = 0;
1232    }
1233    if (curtime.slice(2,3)!=":")
1234    {
1235        bcorrect = 0;
1236    }
1237    if (curtime.slice(5,6)!=":")
1238    {
1239        bcorrect = 0;
1240    }
1241    if(isNumber(curtime.slice(0,2)))
1242    {
1243        if((curtime.slice(0,2)<0) || (curtime.slice(0,2)>23))
1244        {
1245            bcorrect = 0;
1246        }
1247    }else{
1248        bcorrect = 0;
1249    }
1250    //check minutes
1251    if(isNumber(curtime.slice(3,5)))
1252    {
1253        if((curtime.slice(3,5)<0) || (curtime.slice(3,5)>59))
1254        {
1255            bcorrect = 0;
1256        }
1257    }else{
1258        bcorrect = 0;
1259    }
1260    //check seconds
1261    if(isNumber(curtime.slice(6,8)))
1262    {
1263        if((curtime.slice(6,8)<0) || (curtime.slice(6,8)>59))
1264        {
1265            bcorrect = 0;
1266        }
1267    }else{
1268        bcorrect = 0;
1269    }
1270
1271    return bcorrect;
1272}
1273
1274//-->

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.