function isDate (theStr) {
var the1st = theStr.indexOf('-');
var the2nd = theStr.lastIndexOf('-');
if (the1st == the2nd) { return(false); }
else {
var y = theStr.substring(0,the1st);
var m = theStr.substring(the1st+1,the2nd);
var d = theStr.substring(the2nd+1,theStr.length);
var maxDays = 31;
if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {
return(false); }
else if (y.length < 4) { return(false); }
else if (!isBetween (m, 1, 12)) { return(false); }
else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
else if (m==2) {
if (y % 4 > 0) maxDays = 28;
else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
else maxDays = 29;
}
if (isBetween(d, 1, maxDays) == false) { return(false); }
else { return(true); }
}
}
var the1st = theStr.indexOf('-');
var the2nd = theStr.lastIndexOf('-');
if (the1st == the2nd) { return(false); }
else {
var y = theStr.substring(0,the1st);
var m = theStr.substring(the1st+1,the2nd);
var d = theStr.substring(the2nd+1,theStr.length);
var maxDays = 31;
if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {
return(false); }
else if (y.length < 4) { return(false); }
else if (!isBetween (m, 1, 12)) { return(false); }
else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
else if (m==2) {
if (y % 4 > 0) maxDays = 28;
else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
else maxDays = 29;
}
if (isBetween(d, 1, maxDays) == false) { return(false); }
else { return(true); }
}
}
解决方案 »
- 如何在点击一个下拉框的同时,访问数据库改变另一个下拉框的内容
- google浏览器 怎么取fileupload路径
- 网页左右滚动图片新闻怎么做?
- 新手求救:怎么用javascript动态生成一个有若干行的table??
- JAVA大型在线客服系统开发
- 请教大神jquery里ajax的同步和异步的问题
- 谁帮我做一个课程表修改程序!(急)
- 如何实现在表单中按一个按钮,不是本页面转道提交页面,而是弹出提交页面,而本页面不变
- 关于文本框只能输入数字一问?
- 高手请进。html+javascript+IBMwebshpere在jsp区没人能解的问题!
- Javascript密码验证的一个问题
- 请教高手:javascript怎么判断一个文本框获得了焦点?很急!!!!!!
<head>
<title></title>
<script language="JavaScript">
<!--
var MonthDays={
1 : 31,
2 : 28,
3 : 31,
4 : 30,
5 : 31,
6 : 30,
7 : 31,
8 : 31,
9 : 30,
10 : 31,
11 : 30,
12 : 31
};
var CheckDay={
IsLeapyear : function (year) {
if((year%4 == 0) || ((year%100 == 0) && (year%400 == 0)))
return true;
else
return false;
},
GetDate : function (year, month, date) {
var isYearValid = /\d{4}/.test(year) ? true : false;
var isMonthValid = /[1-12]/.test(month) ? true : false;
if(CheckDay.IsLeapyear(year)) {
MonthDays[2] = 29;
}
var isDateValid = ((date <= MonthDays[month]) && (date > 0)) ? true : false;
var result = isYearValid && isMonthValid && isDateValid;
alert(result);
}
}
//-->
</script>
</head>
<body>
<input type="button" value="check" onclick="CheckDay.GetDate('2000', '3', '29');">
</body>
</html>
var CheckDay={
IsLeapyear : function (year) {
return ((year%4 == 0) || ((year%100 == 0) && (year%400 == 0))) ? true : false;
},
IsValid : function (year, month, date) {
var isYearValid = /\d{4}/.test(year) ? true : false;
var isMonthValid = ((month <= 12) && (month > 0)) ? true : false;
if(CheckDay.IsLeapyear(year))
MonthDays[2] = 29;
var isDateValid = ((date <= MonthDays[month]) && (date > 0)) ? true : false;
var result = isYearValid && isMonthValid && isDateValid
alert(result);
}
}
<input type="button" value="check" onclick="CheckDay.IsValid('2000', '2', '29');">