Skip to content

Instantly share code, notes, and snippets.

@m-coding
Last active January 22, 2024 06:36
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save m-coding/c96d99558a47d30aef4992c6dd60437a to your computer and use it in GitHub Desktop.
Save m-coding/c96d99558a47d30aef4992c6dd60437a to your computer and use it in GitHub Desktop.
javascript regex to match date pattern YYYY-MM-DD
// allows YYYY/M/D and periods instead of slashes
// http://stackoverflow.com/questions/24989065/trying-to-validate-yyyy-mm-dd
/^\d{4}[\/.]\d{1,2}[\/.]\d{1,2}$/
// YYYY-MM-DD and YYYY-M-D
// http://stackoverflow.com/questions/6177975/how-to-validate-date-with-format-mm-dd-yyyy-in-javascript
/^\d{4}\-\d{1,2}\-\d{1,2}$/
// YYYY-MM-DD
// https://gist.github.com/arth2o/8471150
/(\d{4})-(\d{2})-(\d{2})/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment