PageSourceSearch

http://www.biharcommercialtax.gov.in:7778/bweb/script/DateValidation.js

js biharcommercialtax.gov.in collected 2026-10-04 04:48:56 UTC 16,822 bytes, 730 lines download raw bytes

1/* THIS BELOW FUNCTION CHECKS THE DATE WETHER IT IS CORRECT DATE OR NOT. 
2INTERNALLY IT CALLS chkdate(objName) function  */
3
4var tempdate;
5
6
7//Added by rankir
8//To compare 2 dates. if date is same returns true else false.
9function checkSameDate(dateFirst,dateSecond)
10{
11	while(dateFirst.charAt(0)==' ')
12				dateFirst=dateFirst.substring(1,dateFirst.length );
13				
14	while(dateFirst.charAt(dateFirst.length-1)==' ')
15				dateFirst=dateFirst.substring(0,dateFirst.length-1);
16				
17	while(dateSecond.charAt(0)==' ')
18				dateSecond=dateSecond.substring(1,dateSecond.length );
19				
20	while(dateSecond.charAt(dateSecond.length-1)==' ')
21				dateSecond=dateSecond.substring(0,dateSecond.length-1);
22				
23	if(dateFirst==dateSecond)
24	{
25		
26		return true;
27	}
28	else
29	{
30		return false;
31	}
32}
33function checkdate(objName)
34{
35    var datefield = objName;
36 
37    if (trim(objName.value) != 'dd/mm/yyyy' || trim(objName.value) == '')
38    {
39       if (chkdate(objName) == false)
40       {
41
42		  datefield.select();
43		  
44          alert("Please fill in dd/mm/yyyy format");
45         
46          datefield.focus();
47         return false;
48       }
49       else 
50       {  
51		
52          return true;
53       }
54    }
55}
56
57function chkdate(objName) {
58  	
59  	 var strDate;
60	var strDateArray;
61	var strDay;
62	var strMonth;
63	var strYear;
64	var intday;
65	var intMonth;
66	var intYear;
67	var booFound = false;
68	var datefield = objName;
69	var strSeparatorArray = new Array("-"," ","/",".");
70	var intElementNr;
71	var err = 0;
72        var curdate=new Date();
73         var comparedate;
74	var strMonthArray = new Array(12);
75	strMonthArray[0] = "Jan";
76	strMonthArray[1] = "Feb";
77	strMonthArray[2] = "Mar";
78	strMonthArray[3] = "Apr";
79	strMonthArray[4] = "May";
80	strMonthArray[5] = "Jun";
81	strMonthArray[6] = "Jul";
82	strMonthArray[7] = "Aug";
83	strMonthArray[8] = "Sep";
84	strMonthArray[9] = "Oct";
85	strMonthArray[10] = "Nov";
86	strMonthArray[11] = "Dec";
87	strDate = trim(datefield.value);
88
89 	if (strDate.length < 6) {
90	return false;
91	}
92	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
93	if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
94	strDateArray = strDate.split(strSeparatorArray[intElementNr]);
95	if (strDateArray.length != 3) {
96	err = 1;
97	return false;
98	}
99	else {
100	strDay = strDateArray[0];
101	strMonth = strDateArray[1];
102	strYear = strDateArray[2];
103	}
104	booFound = true;
105 	  }
106	}
107	if (booFound == false) {
108	if (strDate.length>5) {
109	strDay = strDate.substr(0, 2);
110	strMonth = strDate.substr(2, 2);
111	strYear = strDate.substr(4);
112	   }
113	}
114      
115
116        if (strYear.length == 3) {
117	return false;
118	}
119	if (strYear.length == 2) {
120	strYear = '20' + strYear;
121	}
122
123  
124	intday = parseInt(strDay, 10);
125	if (isNaN(intday)) {
126	err = 2;
127	return false;
128	}
129	intMonth = parseInt(strMonth, 10);
130	if (isNaN(intMonth)) {
131	for (i = 0;i<12;i++) {
132	if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
133	intMonth = i+1;
134	strMonth = strMonthArray[i];
135	i = 12;
136	   }
137	}
138	if (isNaN(intMonth)) {
139	err = 3;
140	return false;
141	   }
142	}
143	intYear = parseInt(strYear, 10);
144	if (isNaN(intYear)) {
145	err = 4;
146	return false;
147	}
148	if (intMonth>12 || intMonth<1) {
149	err = 5;
150	return false;
151	}
152	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
153	err = 6;
154	return false;
155	}
156	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
157	err = 7;
158	return false;
159	}
160	if (intMonth == 2) {
161	if (intday < 1) {
162	err = 8;
163	return false;
164	}
165	if (LeapYear(intYear) == true) {
166	if (intday > 29) {
167	err = 9;
168	return false;
169	}
170	}
171	else {
172	if (intday > 28) {
173	err = 10;
174	return false;
175	}
176	}
177	}
178  
179     tempdate=strDay +"/"+intMonth+"/"+strYear;         
180//     datefield.value = strDay +"/"+intMonth+"/"+strYear;
181     datefield.value = strDay +"/"+strMonth+"/"+strYear;
182       
183	return true;
184	}
185
186
187	function LeapYear(intYear) {
188	if (intYear % 100 == 0) {
189	if (intYear % 400 == 0) { return true; }
190	}
191	else {
192	if ((intYear % 4) == 0) { return true; }
193	}
194	return false;
195	}
196// whitespace characters only.
197
198function isWhitespace (s)
199
200{   var i;
201
202
203
204    // whitespace characters
205    var whitespace = " \t\n\r";	
206
207    // Is s empty?
208    if (isEmpty(s)) return true;
209
210    // Search through string's characters one by one
211    // until we find a non-whitespace character.
212    // When we do, return false; if we don't, return true.
213
214    for (i = 0; i < s.length; i++)
215    {   
216        // Check that current character isn't whitespace.
217        var c = s.charAt(i);
218
219        if (whitespace.indexOf(c) == -1) return false;
220    }
221
222
223    // All characters are whitespace.
224    return true;
225}
226
227
228function isEmpty(s)
229{   return ((s == null) || (s.length == 0))
230}
231// THIS BELOW FUNCTION CHECKS WETHER ENTERED DATE IS BEFORE SYSDATE OR NOT
232
233function doSysdateCheck(from)
234{ 
235 var passmonth;
236var passyear;
237var passday;     
238 var curdate=new Date();
239 var curmonth=parseInt(curdate.getMonth()+1);
240
241 var curyear=parseInt(curdate.getYear());
242 
243 var curday=parseInt(curdate.getDate());
244 var todayDate = curday+"/"+curmonth+"/"+curyear;
245
246 if(from.value!="")
247  {
248	  
249	 
250		if (!fnCompareDates(from.value,todayDate))
251		{
252	
253			from.value="";
254		 //  from.focus();  
255		  return false;
256		}
257		else
258		   { 
259		  return true;
260		   }
261		
262	    
263	}
264}
265
266// THIS BELOW FUNCTION CHECKS WETHER ENTERED DATE IS BEFORE SYSDATE OR NOT
267
268function doSysdateFutureCheck(from)
269{ 
270 var passmonth;
271var passyear;
272var passday;     
273 var curdate=new Date();
274 var curmonth=parseInt(curdate.getMonth()+1);
275
276 var curyear=parseInt(curdate.getYear());
277 
278 var curday=parseInt(curdate.getDate());
279 var todayDate = curday+"/"+curmonth+"/"+curyear;
280 if (chkdate(from) == false)
281    {
282     alert("Please fill in dd/mm/yyyy format");
283     from.value = "";
284     from.focus();
285		return false;
286     }
287    else  
288    {
289    if (!fnCompareDates(todayDate,from.value))
290    {
291   
292       alert("Date must occur after Today's  date.");
293       from.value="";
294       from.focus();
295		return false;
296    }
297    else
298       { 
299      return true;
300       }
301    
302   } 
303}
304
305function validPrd(D1,D2,msg)
306{
307       if(D1.value == "")
308       {
309          alert("Please also fill in "+msg+" from date");
310          return false;
311       }   
312
313       if(D2.value == "")
314       {
315          alert("Please also fill in "+msg+" to date");
316          return false;
317       }
318
319       if(!checkdate(D1))
320          return false;
321
322       if(!checkdate(D2))
323          return false;
324       fdate=D1.value;
325       tdate=D2.value;
326
327       if(!fnCompareDates(fdate,tdate)) 
328       {   
329          alert("Please enter a valid date, "+msg+" to date can not be less than from date");
330          return false;
331       }   
332     
333       return true;
334}
335
336/* start of  Functions written by Jayasheela */
337
338// following function checks whether given is a leap year or not  
339function leapYear(year)
340{
341  if (year % 4 == 0)
342     return true;
343
344  return false;
345}
346
347// following function gives no.of days in the given month of given year
348function getDays(month,year)
349{
350    var ar = new Array(12)
351
352    ar[0] = 31
353    ar[1] = (leapYear(year)) ? 29 : 28 //February
354    ar[2] = 31
355    ar[3] = 30
356    ar[4] = 31
357    ar[5] = 30
358    ar[6] = 31
359    ar[7] = 31
360    ar[8] = 30
361    ar[9] = 31
362    ar[10] = 30
363    ar[11] = 31
364
365   // return number of days in the specified month(parameter)
366   return ar[month] 
367}
368// following function checks given date is valid instrument date or not
369function checkInstrDate(instrdt)
370{ 
371  
372   var priordate,postdate;  
373   var curdate=new Date();
374   var curmonth=parseInt(curdate.getMonth()+1);
375   var curyear=parseInt(curdate.getYear());
376   var curday=parseInt(curdate.getDate());
377
378
379    if (chkdate(instrdt) == false)
380    {
381     alert("Please fill in dd/mm/yyyy format");
382        return false;
383    }
384    else  
385    {
386       // post date checking (end of the current month)
387          postdate=curmonth+"/"+getDays(curmonth-1,curyear)+"/"+curyear; 
388
389       // date before six months
390         if ( curmonth <= 6)
391         {
392           curmonth= (curmonth - 6)+12;
393           curyear = curyear -1;
394         }   
395         else
396	 {
397           curmonth = curmonth - 6;
398         }
399 
400         priordate=curmonth+"/"+curday+"/"+curyear; 
401            
402
403        if (  (Date.parse(priordate) < Date.parse(tempdate))  && 
404                   (Date.parse(postdate) >= Date.parse(tempdate)) )
405        {
406           return true;
407        }
408        else
409        {
410           alert("Instrument date is invalid.Please enter valid date");
411           return false;
412        }
413   }
414
415} 
416
417
418
419/* Following function checks whether the first date is greater than the 
420   second date or not. if first date is greater than second date it returns
421   false and else it returns true
422
423   date values should be passed as first and second
424    (ex:  fnCompareDates(txt_fromdate.value,txt_todate.value); ) */
425
426
427/***   start of fnCompareDates ****/
428
429function fnCompareDates(first,second)
430{
431        var val1;
432        var val2;
433
434	var k = first.indexOf("/");
435        var t = first.indexOf("/",3);     
436        val1 = first.substr(k+1,t-k-1) +"/"+first.substr(0,k)+"/"+first.substr(t+1,first.length);
437      
438	k = second.indexOf("/");
439	t = second.indexOf("/",3);
440	val2 = second.substr(k+1,t-k-1) +"/"+second.substr(0,k)+"/"+second.substr(t+1,second.length);
441	
442        if (Date.parse(val1) > Date.parse(val2))
443         { 
444          // alert("in if");
445           return false; 
446        }
447        else
448        { 
449          //alert("in else");
450          return true;           
451        }
452}
453
454/***  end of fnCompareDates ****/
455
456function dateCheck(dt)
457{
458   if(dt.value.length != 0)
459   {
460     if (dt.value != "dd/mm/yyyy")
461     {
462      if((dt.value.length < 6) || (dt.value.length >= 6 && !chkdate(dt)))
463      {
464         alert("Please fill in a valid date ");
465         dt.value = "";
466         dt.focus();
467         //return false;
468      }
469     } 
470   }   
471   return true;
472}
473
474
475function valFromToDate(from, to, fromName, toName, whichFld) 
476{
477  var name;
478 // if (from.value != "dd/mm/yyyy" && to.value != "dd/mm/yyyy" 
479//      && from.value != "" && to.value != "")
480  //{
481      if (from.value != "dd/mm/yyyy" )
482      {
483        if (doSysdateCheck(from) == false)
484        {
485          from.value="dd/mm/yyyy";
486         // from.focus();
487          //return false;
488        }
489      }
490      if (to.value != "dd/mm/yyyy" && to.value != "")
491      {
492        if (doSysdateCheck(to) == false)
493        {
494          to.value="dd/mm/yyyy"; 
495        //  to.focus();
496         // return false;
497        }
498      }
499
500      if (Date.parse(from.value) > Date.parse(to.value) )
501      {
502        {
503          alert(toName+" date must occur after the "+fromName+" date.");
504          if (whichFld == "from")
505            from.value="dd/mm/yyyy";
506          else
507            to.value = "dd/mm/yyyy";
508            
509          return false;
510        }
511        
512        return true;
513      }
514  // }
515}
516
517
518/* Following function gives the difference between the dates
519   in the months
520
521   date values should be passed as first and second
522    (ex:  fn_DateDiff(txt_fromdate.value,txt_todate.value); ) */
523
524
525/***   start of fn_DateDiff ****/
526
527function fn_DateDiff(first,second)
528{
529        var strDate1;
530        var strDate2;
531	var idateDiff = 0;
532
533	var k = first.indexOf("/");
534        var t = first.indexOf("/",3);     
535        strDate1 = first.substr(k+1,t-k-1) +"/"+first.substr(0,k)+"/"+first.substr(t+1,first.length);
536      
537	k = second.indexOf("/");
538	t = second.indexOf("/",3);
539	strDate2 = second.substr(k+1,t-k-1) +"/"+second.substr(0,k)+"/"+second.substr(t+1,second.length);
540	
541    
542        datDate1= Date.parse(strDate1);
543        datDate2= Date.parse(strDate2);
544    
545        idateDiff = Math.round((datDate2-datDate1)/(29*24*60*60*1000));    
546    
547        return idateDiff;           
548}
549
550/***   End of fn_DateDiff ****/
551
552
553
554
555
556
557
558
559/* Following function gives the difference between the date and the system date
560   in the years
561   date value should be passed as date value
562    (ex:  fn_getDiffinYears(txt_date.value); ) */
563
564
565/********* Start of fn_getDiffinYears ******************/
566
567function fn_getDiffinYears(datevalue)
568{
569     var diff = 0 ;
570
571     var k = datevalue.indexOf("/");
572     var t = datevalue.indexOf("/",3);     
573     var val1 = datevalue.substr(k+1,t-k-1) +"/"+datevalue.substr(0,k)+"/"+datevalue.substr(t+1,datevalue.length);
574	
575     var firstDate = new Date() ;
576     var secondDate = new Date(val1);
577
578     var firstYear = firstDate.getYear();
579     var secondYear = secondDate.getFullYear();
580     if (firstYear < secondYear) { fisrtYear = firstYear + 100; } //Account for some browsers & Y2K
581     var years = firstYear - secondYear;
582
583     var firstMonth = firstDate.getMonth();
584     var secondMonth = secondDate.getMonth();
585
586     if (firstMonth < secondMonth) { diff = (years - 1); }
587     if (firstMonth > secondMonth) { diff = years; }
588     if (firstMonth == secondMonth) 
589     {  
590         var firstDay = firstDate.getDate();
591         var secondDay = secondDate.getDate();
592         if (firstDay < secondDay) { diff = (years - 1); } 
593         if (firstDay >= secondDay) { diff =years; }  
594     }
595     return diff;
596}
597
598/******************* End of fn_getDiffinYears ******************/
599
600
601/* Following function checks the difference between the date given and the system date
602   is greater than 18 years or not . If not gives an alert.
603
604   date object  should be passed as parameter
605
606    (ex:  fn_checkBirthDay(txt_Bdate); ) */
607
608/*******************  Start of fn_checkBirthDay ****************/
609function fn_checkBirthDay(Birthday)
610{
611  if (doSysdateCheck(Birthday) && fn_getDiffinYears(Birthday.value) < 18)
612	{
613            alert("Age of the person is less than 18 years");
614            return false;
615	}
616  return true;
617  
618}
619/*******************  End of fn_checkBirthDay  ***************/
620
621
622/* Following function checks whether the VAT commencement date is after
623   the entered date or not. If the VAT Commencement date is after the entered
624   date then error message is shown
625
626   date object of the entered date and VAT Commencement date value  should be passed as parameters
627
628    (ex:  fn_checkVATCmncDate(txt_effDate,csVATCmncDt); ) */
629    
630/*******************  Start of fn_checkVATCmncDate ****************/
631function fn_checkVATCmncDate(EntdDt,VatCmncDt)
632{
633  if (!fnCompareDates(VatCmncDt,EntdDt.value))
634  {
635    alert(arrstrAlert[67]);
636    EntdDt.value = "";
637  }
638}
639/*******************  End of fn_checkVATCmncDate  ***************/
640
641
642
643function doSysdateCheckArr(arr){
644	var i,j=0;
645	var msg="";
646	var iValid=true;;
647	var focusfield;
648	var bFlag=false;
649
650	for(i=0;i<arr.length;i++){
651		
652	var field = arr[i][0];
653	
654	bFlag=doSysdateCheck(field);
655							
656		if (bFlag==false) {
657			
658			msg=msg+arr[i][1]+"\n";
659			iValid=false;
660		}
661	
662	}
663	if(iValid==false)
664	{
665		alert(msg);
666	}
667	return iValid;
668}
669
670function Trim(text)
671	{
672		LTrim(text);
673		RTrim(text);
674	}
675	function LTrim(text)
676	{
677			while(text.value.charAt(0)==' ')
678				text.value=text.value.substring(1,text.value.length );
679	}
680	function RTrim(text)
681	{
682			while(text.value.charAt(text.value.length-1)==' ')
683				text.value=text.value.substring(0,text.value.length-1);
684	}
685	
686
687
688	// THIS BELOW FUNCTION CHECKS WETHER ENTERED DATE IS BEFORE SYSDATE OR NOT
689
690function doSysdatePreviousCheck(from,message)
691{ 
692 	var passmonth;
693	var passyear;
694	var passday;
695	
696 var curdate =document.getElementById('todaydate').value;
697 var dateArray=new Array();
698 dateArray=curdate.split('/');
699 
700 var curyear=dateArray[2];
701 var curmonth=dateArray[1];
702 var curday=dateArray[0];
703 /*var curmonth=parseInt(curdate.getMonth()+1);
704 var curyear=parseInt(curdate.getFullYear());
705 var curday=parseInt(curdate.getDate());*/
706 var todayDate = curday+"/"+curmonth+"/"+curyear;
707 //alert("******todayDate:"+todayDate);
708 //alert(from.value+","+todayDate);
709 if (chkdate(from) == false)
710    {
711     alert("Please fill in dd/mm/yyyy format");
712     //from.value = "";
713  //   from.focus();
714		return false;
715     }
716    else  
717    {
718    if (!fnCompareDates(from.value,todayDate))
719    {
720       alert(message + " must occur before Today's  date.");
721       from.value="";
722		return false;
723    }
724    else
725       { 
726      return true;
727       }
728    
729   } 
730}

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.