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); }
}
}

解决方案 »

  1.   

    <html>
    <head>
    <title></title>
    <script language="JavaScript">
    <!--
    var MonthDays={
    1 : 31,
    2 : 28,
    3 : 31,
    4 : 30,
    5 : 31,
    6 : 30,
    7 : 31,
    8 : 31,
    9 : 30,
    10 : 31,
    11 : 30,
    12 : 31
    };
    var CheckDay={
    IsLeapyear : function (year) {
    if((year%4 == 0) || ((year%100 == 0) && (year%400 == 0)))
    return true;
    else
    return false;
    },
    GetDate : function (year, month, date) {
    var isYearValid = /\d{4}/.test(year) ? true : false;
    var isMonthValid = /[1-12]/.test(month) ? true : false;
    if(CheckDay.IsLeapyear(year)) {
    MonthDays[2] = 29;
    }
    var isDateValid = ((date <= MonthDays[month]) && (date > 0)) ? true : false;
    var result = isYearValid && isMonthValid && isDateValid;
    alert(result);
    }
    }
    //-->
    </script>
    </head>
    <body>
    <input type="button" value="check" onclick="CheckDay.GetDate('2000', '3', '29');">
    </body>
    </html>
      

  2.   

    其实你可以用一个万年历来实现日期的选择啊,我以前就改过一个,需要的话留下EMAIL
      

  3.   

    不好意思,上面的有错误
    var CheckDay={
    IsLeapyear : function (year) {
    return ((year%4 == 0) || ((year%100 == 0) && (year%400 == 0))) ? true : false;
    },
    IsValid : function (year, month, date) {
    var isYearValid = /\d{4}/.test(year) ? true : false;
    var isMonthValid = ((month <= 12) && (month > 0)) ? true : false;
    if(CheckDay.IsLeapyear(year))
    MonthDays[2] = 29;
    var isDateValid = ((date <= MonthDays[month]) && (date > 0)) ? true : false;
    var result = isYearValid && isMonthValid && isDateValid
    alert(result);
    }
    }
    <input type="button" value="check" onclick="CheckDay.IsValid('2000', '2', '29');">