JS判断是否为“YYYYMMDD”式的日期

function isDate8(sDate) {

        if (!/^[0-9]{8}$/.test(sDate)) {

            return false;

        }

        var year, month, day;

        year = sDate.substring(0, 4);

        month = sDate.substring(4, 6);

        day = sDate.substring(6, 8);

        var iaMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

        if (year < 1700 || year > 2500) return false

        if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1] = 29;

        if (month < 1 || month > 12) return false

        if (day < 1 || day > iaMonthDays[month - 1]) return false

        return true

    }

  

posted @ 2019-05-03 15:17  yvioo  阅读(2182)  评论(0编辑  收藏  举报