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

    }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM