Skip to content

Instantly share code, notes, and snippets.

@morjuax
Created July 4, 2022 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morjuax/482c4f4cf7b3c93cdf4b65a031276ee4 to your computer and use it in GitHub Desktop.
Save morjuax/482c4f4cf7b3c93cdf4b65a031276ee4 to your computer and use it in GitHub Desktop.
Validate date with regex
const date_regex = /^(0[1-9]|1\d|2\d|3[01])\/(0[1-9]|1[0-2])\/(19|20)\d{2}$/; // dd/mm/yyyy
const date_regex2 = /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/; // mm/dd/yyyy
const testDate = '13/06/2022';
date_regex.test('01/12/2022')
date_regex2.test('12/30/2022')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment