functionisDateValid(dateString) {
// First, check if the input is a valid date formatif (!/^\d{4}-\d{2}-\d{2}$/.test(dateString)) {
returnfalse;
}
// Second, check if the date is an actual valid dateconst dateObj = newDate(dateString);
return !isNaN(dateObj.getTime());
}
// Example usageconsole.log(isDateValid('2022-12-25')); // Output: trueconsole.log(isDateValid('2022-13-25')); // Output: false