dayjs / dayjs-website

⏰Day.js website repo
http://day.js.org/
MIT License
65 stars 228 forks source link

"isValid" returns true on invalid date. #46

Closed Cerceis closed 3 years ago

Cerceis commented 3 years ago
        const testDate = "2021-07-07"
        console.log(dayjs(testDate).isValid())
        //Output : true
        const testDate = "abc07-07"
        console.log(dayjs(testDate).isValid())
        //Output : false
        const testDate = "abc-07-07"
        console.log(dayjs(testDate).isValid())
        //Output : true <-- Problem

Or does it intended to only check for the date format ?

iamkun commented 3 years ago

isValid only checks if it's a valid date to Date object.

You may specify a boolean for the last argument to use strict parsing. Strict parsing requires that the format and input match exactly, including delimiters. https://day.js.org/docs/en/parse/string-format