當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JS验证日期【闰年月大月小】
生活随笔
收集整理的這篇文章主要介紹了
JS验证日期【闰年月大月小】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
JS驗證日期【閏年月大月小】 function checkDate() {var strDate = document.myform.txtTime.value;if (strDate != "") {var reg = /^\d{4}-(0[1-9]|1[0-2])-(0[0-9]|1[0-9]|2[0-9]|3[0-1])$/;if (reg.test(strDate)) {strayy = strDate.split("-");if (strayy[1] == 2) {if (strayy[0] % 4 == 0) {if (strayy[2] > 29) {alert("閏年2月只有29天,請重新輸入。");return false;}else {return true;}}else {if (strayy[2] > 28) {alert("平年2月只有28天,請重新輸入。");return false;}else {return true;}}}else {if (strayy[1] == 4 || strayy[1] == 6 || strayy[1] == 9 || strayy[1] == 11) {if (strayy[2] > 30) {alert(strayy[1] + "月只有30天,請重新輸入。");return false;} else {return true;}}}}else {alert("輸入日期格式不正確\n請重新輸入!");document.myform.txtTime.focus();return false;}}else {alert("輸入不能為空!");document.myform.txtTime.focus();return false;}
}
?
posted on 2013-11-11 22:26? 醉清風2 閱讀( ...) 評論( ...) 編輯 收藏轉載于:https://www.cnblogs.com/JPSite/p/3418602.html
總結
以上是生活随笔為你收集整理的JS验证日期【闰年月大月小】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CorelDRAW2023最新版本配置及
- 下一篇: Husky数据分析——招聘信息背后的潜规