还有
<script>
function strDate(str){
var reg = /^(\d{1,4})(-|\/)(\d{1,2})\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]);
var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate()
return newStr==str
}
alert(strDate("2002-1-31"))
alert(strDate("2002-2-31"))
alert(strDate("2002-1-41"))
</script>
<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:64:56"))
alert(strDateTime("2002-1-41 12:00:00"))
</script>
<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:64:56"))
alert(strDateTime("2002-1-41 12:00:00"))
</script>
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); }
}
}
/*****************************************************************
*检查日期格式是否是一个有效的时间格式
*****************************************************************/
function isTime (theStr) {
var colonDex = theStr.indexOf(':');
if ((colonDex<1) || (colonDex>2)) { return(false); }
else {
var hh = theStr.substring(0,colonDex);
var ss = theStr.substring(colonDex+1, theStr.length);