Categories
JavaScript Answers

How to check if date is a valid one with JavaScript?

Spread the love

Sometimes, we want to check if date is a valid one with JavaScript.

In this article, we’ll look at how to check if date is a valid one with JavaScript.

How to check if date is a valid one with JavaScript?

To check if date is a valid one with JavaScript, we can use the moment.js’ isValid function.

For instance, we write

const date = moment("2022-10-19").isValid();

to call moment with a date string.

Then we call isValid to check if the date string is a valid one.

Conclusion

To check if date is a valid one with JavaScript, we can use the moment.js’ isValid function.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *