<script language= "JavaScript" >
Verify that the given date is valid and that the parameter format requires: YYYY-MM-DD can correct the expression according to the situation
function IsDate (ostartdate)
{
Validation of date formats requires a 2000-2,099 format of YYYY-MM-DD and can be converted to the correct date correctly
var pat_hd=/^20/d{2}-((0[1-9]{1}) | ( 1[0-2]{1})-((0[1-9]{1}) | ( [1-2] {1} [0-9] {1}) | (3[0-1]{1})) $/;
try{
The IF (!pat_hd.test (ostartdate)) {Throw date is illegal. ";}
var arr_hd=ostartdate.split ("-");
var datetmp;
datetmp= New Date (Arr_hd[0],parsefloat (arr_hd[1)) -1,parsefloat (arr_hd[2));
if (Datetmp.getfullyear ()!=parsefloat (arr_hd[0)) | | Datetmp.getmonth ()!=parsefloat (arr_hd[1])-1 | | dateTmp.getDate ( )!=parsefloat (arr_hd[2])
{
Throw "date is illegal. ";
}
}
catch (ex)
{
if (ex.description)
{return false;}
Else
{return false;}
}
return true;
}
Call
Alert (IsDate ("2005-12-12"));
Alert (IsDate ("2004-13-30"));
Alert (IsDate ("2005-12-32"));
Alert (IsDate ("2005-02-30"));
</script>