js简单实现输入年月日,并显示出结果

var year=prompt("美女,请输入年份");
if(year!=null)
{
if(isNaN(year))
{
alert("美女,输入的不是数字");
}
else
{
if(isNum(year))
{
if(year>0&&year<=9999)
{
var month=prompt("美女,请输入月份");
if(month!=null)
{
if(isNaN(month))
{
alert("笨蛋,不是数字");
}
else
{
if(isNum(month))
{
if(month>=1&&month<=12)
{
var day=prompt("请输入年月日的日");
if(isNaN(day))
{
alert("不是数字");
}
else
{
if(isNum(day))
{
if(day>=1&&day<=31)
{
if(month==2)
{
if(day>=1&&day<=28)
{
alert("您输入的年月日为:"+year+"年"+month+"月"+day+"日");
}
else if(day==30|day==31)
{
alert("2月份没有30号或者31号");
}
else if(day==29)
{
if((year%4==0&&year%10!=0)|year%400==0)
{
alert("您输入的年月日为:"+year+"年"+month+"月"+day+"日");
}
else
{
alert("小子,平年是没有29号的");
}
}
}
else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
alert("您输入的年月日为:"+year+"年"+month+"月"+day+"日");
}
else if(month==4||month==6||month==9||month==11)
{
if(day==31)
{
alert("4,6,9,11月没有31号");
}
else
{
alert("您输入的年月日为:"+year+"年"+month+"月"+day+"日");
}
}
}
else
{
alert("日只能在1-31之间");
}
}
else
{
alert("请不要输入小数");
}
}
}
else
{
alert("月份只有1-12哦");
}
}
else
{
alert("请不要输入小数");
}
}
}
else
{
alert("小子,记不住吗,不要乱点");
}

}
else
{
alert("不好意思,我们有规定,输入的整数必须是大于0小于等于9999");
}
}
else
{
alert("小子,这是小数!");
}
}
}
else
{
alert("小子,不要乱点");
}


function isNum(s)
{
var regu = "^([0-9]*[.0-9])$"; // 小数测试
var re = new RegExp(regu);
if (s.search(re) != -1)
return true;
else
return false;
}

posted @ 2016-08-23 16:56  火山林风  阅读(1237)  评论(0编辑  收藏  举报