Age calculator app using Next.js, React, React-hook-form and Zod

Solution retrospective
I'm not entirely satisfied with how I made the date validation with vanilla js, since I used Day.js to count the difference between the dates, I thought it would be easy to use it to validate the date as well, but I struggled a lot with it, in the end I just used vanilla js because I couldn't quite get the result I was expecting. Does anyone know how could I have done that?
Please log in to post a comment
Log in with GitHubCommunity feedback
- @ajeetachal
"Great job on completing your project! I appreciate the effort you put into it. It can be challenging to work with new libraries and tools like Day.js, so I understand why you might have struggled with validating dates using it.
However, I'm glad to say that there is a solution! Day.js actually has a built-in method called isValid() that you can use to validate dates. Here's an example of how you could use it:
const dateFormat = 'YYYY-MM-DD'; // set the expected format of the date // check if the date is valid if (dayjs(dateInput, dateFormat).isValid()) { console.log('Valid date!'); } else { console.log('Invalid date.'); }
I hope this solution helps you improve your date validation. Keep up the great work!"
Marked as helpful
Join our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord