在javascript 里面有没有检查日期格式的函数?
发表于:2007-06-30来源:作者:点击数:
标签:
function isdate(strDate){br nbsp;nbsp;nbsp;var strSeparator = quot;-quot;; //日期分隔符br nbsp;nbsp;nbsp;var strDateArray;br nbsp;nbsp;nbsp;var intYear;br nbsp;nbsp;nbsp;var intMonth;br nbsp;nbsp;nbsp;var intDay;br nbsp;nbsp;nbsp;var boolLe
function isdate(strDate){<br>
var strSeparator = "-"; //日期分隔符<br>
var strDateArray;<br>
var intYear;<br>
var intMonth;<br>
var intDay;<br>
var boolLeapYear;<br>
<br>
strDateArray = strDate.split(strSeparator);<br>
<br>
if(strDateArray.length!=3) return false;<br>
<br>
intYear = parseInt(strDateArray[0],10);<br>
intMonth = parseInt(strDateArray[1],10);<br>
intDay = parseInt(strDateArray[2],10);<br>
<br>
if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay)) return false;<br>
<br>
if(intMonth>12||intMonth<1) return false;<br>
<br>
if((intMonth==1||intMonth==3||intMonth==5||intMonth==7||intMonth==8||intMonth==10||intMonth==12)&&(intDay>31||intDay<1)) return false;<br>
<br>
if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30||intDay<1)) return false;<br>
<br>
if(intMonth==2){<br>
if(intDay<1) return false;<br>
<br>
boolLeapYear = false;<br>
if((intYear%100)==0){<br>
if((intYear%400)==0) boolLeapYear = true;<br>
}<br>
else{<br>
if((intYear%4)==0) boolLeapYear = true;<br>
}<br>
<br>
if(boolLeapYear){<br>
if(intDay>29) return false;<br>
}<br>
else{<br>
if(intDay>28) return false;<br>
}<br>
}<br>
<br>
return true;<br>
}<br>
原文转自:http://www.ltesting.net