How to check if a date is valid in JavaScript
Validating date input is a common task when building modern javascript applications, especially when you need code that is easy to read and safe to reuse. As the creator of CoreUI and a developer with over 25 years of experience, I usually prefer the simplest built-in approach that stays explicit in real production code. Use Number.isNaN(date.getTime()) to verify whether a JavaScript Date instance contains a valid timestamp. This keeps the solution approachable while still being reliable enough for components, utilities, and data transformation logic. Below I will show the core snippet first, explain why it works, and point out the most important implementation detail to keep in mind.
Use Number.isNaN(date.getTime()) to verify whether a JavaScript Date instance contains a valid timestamp.
const value = new Date('2026-05-12')
const invalidValue = new Date('not-a-date')
const isValidDate = (date) => !Number.isNaN(date.getTime())
console.log(isValidDate(value))
console.log(isValidDate(invalidValue))
A JavaScript Date object can still exist even when the input string was invalid. Calling getTime() converts the internal value to a timestamp, and invalid dates return NaN. Wrapping that check with Number.isNaN() gives you a reliable way to validate the date before using it in your logic.
Why this works
Invalid JavaScript dates still produce a Date object, so checking the instance type alone is not enough. The reliable signal is the timestamp returned by getTime(), because invalid dates convert to NaN.
Common pitfall
Avoid comparing the string representation of a date to Invalid Date. That pattern is more fragile and less explicit than checking the numeric timestamp directly.
Best Practice Note
This is the same kind of practical, low-complexity approach we prefer in CoreUI components to keep code predictable and easy to maintain.
Related answers
If you are working on similar problems, these guides are good follow-ups:



