checkdate.js
上传用户:huijianzhu
上传日期:2009-11-25
资源大小:9825k
文件大小:2k
- //检查日期型数据 形如"yyyy-mm-dd"
- function isDate(sDate){
- var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]
- var iaDate = new Array(3)
- var year, month, day
- if (arguments.length != 1) return false
- iaDate = sDate.toString().split("-")
- if (iaDate.length != 3){
- alert("请在日报日期中输入正确的日期");
- return false;
- }
- if (iaDate[0].length!=4 || iaDate[1].length > 2 || iaDate[2].length > 2){
- alert("请在日报日期中输入正确的日期");
- return false;
- }
- year = parseFloat(iaDate[0])
- month = parseFloat(iaDate[1])
- day=parseFloat(iaDate[2])
- //alert(year+month+day)
- for(i=0;i<year.length;i++){
- var oneChar = year.charAt(i);
- if (oneChar < "0" || oneChar > "9"){
- alert("请在日报日期中输入正确的日期");
- return false;
- }
- }
- for(i=0;i<month.length;i++){
- var oneChar = year.charAt(i);
- if (oneChar < "0" || oneChar > "9"){
- alert("请在日报日期中输入正确的日期");
- return false;
- }
- }
- for(i=0;i<day.length;i++){
- var oneChar = year.charAt(i);
- if (oneChar < "0" || oneChar > "9"){
- alert("请在日报日期中输入正确的日期");
- return false;
- }
- }
- if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
- if (month < 1 || month > 12){
- alert("请在日报日期中输入正确的日期");
- return false;
- }
- if (day < 1 || day > iaMonthDays[month - 1]){
- alert("请在日报日期中输入正确的日期");
- return false;
- }
- if (year>new Date().getYear() || year==new Date().getYear() && month> new Date().getMonth()+1 || year==new Date().getYear() && month==new Date().getMonth()+1 && day> new Date().getDate()){
- alert("请在日报日期中输入正确的日期,日报日期不能大于当前日期");
- return false;
- }
- return true;
- }