先给一个比较傻的,不过一定有效//--- 方法名: judgeInputDate(AYear,AMonth,ADay)
//--- 功能: 判断输入的年、月、日是否合法,时间范围在1900~2100年之间
//--- 返回: 合法返回1,不合法返回0
//--- AYear : 输入的年份
//--- AMonth: 输入的月份
//--- ADay : 输入的日子
//--- 创建日期: 2001-06-27 最近更新日期: 2001-06-29
//--- 创建程序员: xg_delayth 最近更新程序员: xg_delayth
//--- 维护程序员: xg_delayth
function judgeInputDate(AYear,AMonth,ADay){
var tempYear,tempMonth,tempDay;
//--- 非闰年的每个月天数
var constMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
//--- 一般输入性判断
if ((AYear.length > 4) || (AMonth.length > 2)){return 0;}
if ((judgeStringType(AYear,"iNChar") == false) || (judgeStringType(AMonth,"iNChar") == false)
|| (judgeStringType(ADay,"iNChar") == false)){ return 0 }
//--- 取得输入值
tempYear = parseInt(AYear);
if((tempYear > 2100) || (tempYear < 1900)){return 0;}
tempMonth = parseInt(trimSubStr(AMonth,"0",1));
tempDay = parseInt(trimSubStr(ADay,"0",1));
//--- 判断月合法性
if ((tempMonth == 0) || (tempMonth > 12)){return 0;}
if (tempMonth != 2){
if((tempDay > constMonth[tempMonth - 1]) || (tempDay == 0)){return 0;}
} else{ //--- 根据闰年判断
if((tempYear % 4 == 0) && (tempYear % 100 != 0) || (tempYear % 400 == 0)){
if((tempDay > 29) || (tempDay == 0)){return 0;}
}else{
if((tempDay > constMonth[1]) || (tempDay == 0)){return 0;}
}
}
return 1
}
//--- 功能: 判断输入的年、月、日是否合法,时间范围在1900~2100年之间
//--- 返回: 合法返回1,不合法返回0
//--- AYear : 输入的年份
//--- AMonth: 输入的月份
//--- ADay : 输入的日子
//--- 创建日期: 2001-06-27 最近更新日期: 2001-06-29
//--- 创建程序员: xg_delayth 最近更新程序员: xg_delayth
//--- 维护程序员: xg_delayth
function judgeInputDate(AYear,AMonth,ADay){
var tempYear,tempMonth,tempDay;
//--- 非闰年的每个月天数
var constMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
//--- 一般输入性判断
if ((AYear.length > 4) || (AMonth.length > 2)){return 0;}
if ((judgeStringType(AYear,"iNChar") == false) || (judgeStringType(AMonth,"iNChar") == false)
|| (judgeStringType(ADay,"iNChar") == false)){ return 0 }
//--- 取得输入值
tempYear = parseInt(AYear);
if((tempYear > 2100) || (tempYear < 1900)){return 0;}
tempMonth = parseInt(trimSubStr(AMonth,"0",1));
tempDay = parseInt(trimSubStr(ADay,"0",1));
//--- 判断月合法性
if ((tempMonth == 0) || (tempMonth > 12)){return 0;}
if (tempMonth != 2){
if((tempDay > constMonth[tempMonth - 1]) || (tempDay == 0)){return 0;}
} else{ //--- 根据闰年判断
if((tempYear % 4 == 0) && (tempYear % 100 != 0) || (tempYear % 400 == 0)){
if((tempDay > 29) || (tempDay == 0)){return 0;}
}else{
if((tempDay > constMonth[1]) || (tempDay == 0)){return 0;}
}
}
return 1
}
http://www.csdn.net/expert/topic/697/697297.xml?temp=.2358362
<script>
function strDateTime(str){
var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
var r = str.match(reg);
if (r==null)return false;
var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate()+" "+d.getHours()+":"+d.getMinutes()+":"
+d.getSeconds()
return newStr==str
}
alert(strDateTime("2002-1-31 12:34:56"))
alert(strDateTime("2002-1-31 12:54:56"))
alert(strDateTime("2002-1-41 12:00:00"))
</script>