Skip to content

Instantly share code, notes, and snippets.

@emmiep
Created July 2, 2021 17:49
Show Gist options
  • Save emmiep/80b124115082342a47f48d5cdd65a2d2 to your computer and use it in GitHub Desktop.
Save emmiep/80b124115082342a47f48d5cdd65a2d2 to your computer and use it in GitHub Desktop.
JS validate date
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