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); }
}
}
解决方案 »
- 字符转成数组
- javaScript button的onclick调用函数没有反应??
- Javascript事件问题,帮忙给个思路!
- 为什么load加载XML,总是失败!!!
- 两个HTM文件之间如何传递变量值? ASP文件的变量值如何传到客户端javascript的变量?(在线等候,不解决永远顶!)
- 又一个有关IFrame的问题,望各位高手指教
- 请教:如何在javascript中获得服务器的ip地址?
- 谁知道1个标准字符占几个像素?
- 寄给晕了几个小时的朋友,寄给晕了几个小时的朋友
- ■■各位大侠,高分请教JSP一个问题,一定加分!■■
- 怎样往xml文件中指定的位置写一行?
- 这个cookies怎么改写成javascript server 断的?
//
function IsDate(s) {
var re = /^(\d{4})(\/|-)(\d{1,2})\2(\d{1,2})$/
var m = re.exec(s);
if (m == null) return false;
var d = new Date(m[1],m[3]-1,m[4]);
return d.getFullYear()==m[1] && d.getMonth()==(m[3]-1) && d.getDate()==m[4];
}
alert(IsDate("2005-2-28"))
</script>
var objRegExp = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
if(!objRegExp.test(strValue))
return false;
else{
var arrayDate = strValue.split(RegExp.$1);
var intDay = parseInt(arrayDate[2],10);
var intYear = parseInt(arrayDate[0],10);
var intMonth = parseInt(arrayDate[1],10); if(intMonth > 12 || intMonth < 1) {
return false;
} var arrayLookup = { '1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31,
'8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31} if(arrayLookup[parseInt(arrayDate[1])] != null) {
if(intDay <= arrayLookup[parseInt(arrayDate[1])] && intDay != 0)
return true;
} if (intMonth-2 ==0) {
var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
return true;
}
}
return false;
}