<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script>
<!--
function checkDate(value)
{
if((/^\d{4}-\d{1,2}-\d{1,2}$/).test(value) == false)
return false;
dateArr = value.split("-");
monthPerDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
year = dateArr[0];
month = dateArr[1];
day = dateArr[2];
if(month >12 || month<0)
return false;
if(day>31 || day<0 )
return false;
if(year%100 == 0)
{
if(year%400 == 0)
monthPerDays[1] = 29;
}
else
{
if(year%4 == 0)
monthPerDays[1] = 29;
}
if(monthPerDays[month-1] < day)
return false;
return true;
}
function checkForm()
{
if(!checkDate(document.all.s2.value))
{
alert("请输入正确的日期格式!");
document.all.s2.focus();
return false;
}
else
{
alert("日期格式正确!");
}
}
//-->
</script>
<body>
<input name="s2" type="text" id="s2" value="2011-6-9"/>
<input type="button" name="Submit" value="判断日期格式" οnclick="return checkForm()"/>
</body>
</html>