Saturday, February 6, 2010

Javascript Date validation function

function checkDate(ddlDay,ddlMonth,ddlYear)
{

var d=document.getElementById(ddlDay).value;
var m=document.getElementById(ddlMonth).value;
var y=document.getElementById(ddlYear).value;

var yl=1900; // least year to consider
var ym=2100; // most year to consider
var flag = true;

if (m<1>12) flag=false;
if (d<1>31) flag=false;
if (yym) flag=false;
if (m==4 || m==6 || m==9 || m==11)
if (d==31) flag=false;
if (m==2)
{
var b=parseInt(y/4);
if (isNaN(b)) flag=false;
if (d>29) flag=false;
if (d==29 && ((y/4)!=parseInt(y/4))) flag=false;
}

if(flag)
{
return (true);
}
else
{
return (false);
}

return(true);
}

No comments: