<html>
<head>
<script type="text/javascript">
function valid_date(fdate)
{
//alert('Hii'+fdate);
fdate = f.procdate.value;
//alert(fdate);
strfdate =fdate.split("/");
len=strfdate.length;
if(len!=3)
{
strfdate =fdate.split("-");
len=strfdate.length;
}
fdays=strfdate[0];
fmonth=strfdate[1];
fyear=strfdate[2];
/*alert(fday);
alert(fmonth);
alert(fyear);*/
//alert(len);
if(len!=3)
{
alert("Proceeding Date is not valid. Date Format is DAY-MON-YEAR");
f.procdate.value='';
return false;
}
var maxdays=getmaxdays(fmonth,fyear);
//alert('Max Days:'+maxdays);
if(maxdays<fdays)
{
alert("Days are excceded for the given month in proceeding Date");
f.procdate.value='';
return false;
}
var c=isNaN(fdays);
if(c)
{
alert('Days in Proceeding Date Must be numeric only');
f.procdate.value='';
return false;
}
var c=isNaN(fmonth);
if(c)
{
alert('Month in Proceeding Date Must be numeric only');
f.procdate.value='';
return false;
}
var c=isNaN(fyear);
if(c)
{
alert('Year in Proceeding Date Must be numeric only');
f.procdate.value='';
return false;
}
if(fmonth>12)
{
alert("Month is not valid in proceeding Date");
f.procdate.value='';
return false;
}
else
{
alert('Valid Date');
return true;
}
}
function getmaxdays(mon,year)
{
mon++; mon--; year++; year--;
if(mon==1)
return 31;
else if(mon==2)
{
if ((year % 100) == 0)
{
if ((year % 400) == 0)
return 29;
}
else
if ((year % 4) == 0) return 29;
else
return 28;
}
else if(mon==3)
return 31;
else if(mon==4)
return 30;
else if(mon==5)
return 31;
else if(mon==6)
return 30;
else if(mon==7)
return 31;
else if(mon==8)
return 31;
else if(mon==8)
return 31;
else if(mon==9)
return 30;
else if(mon==10)
return 31;
else if(mon==11)
return 30;
else if(mon==12)
return 31;
}
</script>
</head>
<body>
<form name='f'>
Enter Date: <input type=text name='procdate' id='procdate' maxlength=20 onchange='return valid_date(this.value)'>
</form>
</body>
</html>
0 comments:
Post a Comment