Skip to content

Instantly share code, notes, and snippets.

@FeMaffezzolli
Last active September 4, 2020 19:54
Show Gist options
  • Save FeMaffezzolli/3087b513cf789c70047351f118d150ea to your computer and use it in GitHub Desktop.
Save FeMaffezzolli/3087b513cf789c70047351f118d150ea to your computer and use it in GitHub Desktop.
Is valid date format dd-mm-yyyy
/**
* Receives a date in the following format
*/
function isValidDate(date: string) {
return /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/g.test(date)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment