判断日期格式是否正确

<!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=utf-8" />
<title>日期设置</title>
</head>

<body>
</body>
</html>
分别输入年、月、日。判断日期格式是否正确!!!
<script type="text/javascript">
var year =prompt("请输入一个年份")
if(year!=null)
{
var year1=isNaN(year)
if(year1==false)
{
if(year%1==0&&year>0&&year<9999)
{
var month=prompt("请输入月份")
if(month!=null)
{
var month1=isNaN(month)
if(month1==false)
{
if(month%1==0&&month>0&&month<=12)
{
var date=prompt("请输入日期")
if(date!=null)
{
var date1=isNaN(date)
if(date1==false)
{
if(date%1==0&&date>0&&date<=31)
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
alert("日期格式输入正确,您输入的日期为"+year+"年"+month+"月"+date+"日。")
}
else if(month==4||month==6||month==9||month==11)

{
if (date<31)

{
alert("日期格式输入正确,您输入的日期为"+year+"年"+month+"月"+date+"日。")
}
else{alert("日期格式输入正确,您输入的日期为"+year+"年"+month+"月"+date+"日。")}
}
else(month==2)
{
if(year%4==0&&year%100!=0||year%400==0)
{
if(date>0&&date<=29)
{
alert("日期格式输入正确,您输入的日期为"+year+"年"+month+"月"+date+"日。")
}
else
{
alert("输入有误")
} }
else
{
if(date>0&&date<=28)
{
alert(year+"-"+month+"-"+date)
}
else
{
alert("输入有误")
}
}
}
}
else
{
alert("输入有误")
}
}
else
{
alert("输入有误")
}
}
}
else
{
alert("输入有误")
}
}
else
{
alert("输入有误")
}
}
}
else
{
alert("输入有误")
}
}
else
{
alert("输入有误")
}
}


</script>

posted @ 2016-08-24 11:23  蕤霁雲若  阅读(1887)  评论(0编辑  收藏  举报