Skip to content

Instantly share code, notes, and snippets.

@ChristianRich
Forked from m-coding/regex-yyyy-mm-dd.js
Created July 5, 2017 07:30
Show Gist options
  • Save ChristianRich/b3df7c596c826f8c828830ae79cd778e to your computer and use it in GitHub Desktop.
Save ChristianRich/b3df7c596c826f8c828830ae79cd778e 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