Ideas:

1. Check whether the date format is correct by using the re.

2. Check whether the number of days in February is correct when a leap/regular year is performed.

3. Check whether the number of days in some months exceeds 30.

The code is as follows:

@param {string} date string * @returns True for the correct date. Function verifyDate(date){if (typeof date! == 'string') { return false; } const regExp = /^\d{4}[-./](0? [0-9]) | (1 [012])) /. / (((1-9]) | ([012] [0-9]) | (3 [01])) $/; if (! regExp.test(date)) { return false; } const dates = date.match(/\d+/g); / / dates [0] | 0 implicitly convert data types, such as: 099 | 0 = > 99 const year = dates [0] | 0; const month = dates[1] | 0; const day = dates[2] | 0; If (month === 2) {if (day > 29) {return false; } else if (day === 29) { if (! (year % 4 === 0 && year % 100 ! = = 0) &&! (year % 400 === 0)) { return false; If (day > 30 && [4, 6, 9, 11].indexof (month)! == -1) { return false; } return true; }Copy the code

For the original link, click here.