Created
July 2, 2021 17:49
-
-
Save emmiep/80b124115082342a47f48d5cdd65a2d2 to your computer and use it in GitHub Desktop.
JS validate date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validateDate(year, month, day) { | |
const date = new Date(year, month, day); | |
if (year !== date.getFullYear() || month !== date.getMonth() || day !== date.getDate()) { | |
throw new Error('Invalid date'); | |
} | |
return date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment