<!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>
<script language="javascript">
function isdate(date){//date开始
index1=date.indexof("-");//判断-的位置
if(index==-1){return false}//没有 则输出false
year=date.substring(0,index1);//选择并赋值
date=date.substring(index1+1);//获取从index1+1开始到结束的子段
index1=date.indexof("-");//获取赋值后的date中-的位置
if(index1==-1){return false}//判断 没有则false
month=date.substring(0,index1);//赋值给month
day=date.substring(index1+1);//获取从index1+1开始到结束的子段并赋值给date
if(isNumber(year)&&isNumber(month)&&isNumber(day))//判断 如果是数字 则继续判断 否则 则false
{
if(year<1900||year>9999||month<1||month>12||day<1||day>31) //判断 年份 月份 日期 的值是否正确
return false;
if((mont==4||month==6||month==9||month==11)&&day>30) //判断 4 6 9 11 月份的日期是否正确
return false;
if(month==2){ //判定 2月的特殊情况
if(year%400==0||(year%4==0&&year%400!=0)){
if(day>29) return false;
}
else{
if(day>28) return flase;
}
}
}//if判断结束
else return false;
}//date方法结束
function vf(form){ //vf方法开始
var d=form.date.value;//将表单的date赋值给d
if(!isdate(d)) //判定 如果日期输入错误 则弹出字段
{alert("happen some error");
form.date.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return vf(form1)">
birthday<input type="text" name="date" id="date" />
<input type="submit" value="submit" />
</form>
</body>
</html>
认证高级PHP讲师