Created
July 4, 2022 17:42
-
-
Save morjuax/482c4f4cf7b3c93cdf4b65a031276ee4 to your computer and use it in GitHub Desktop.
Validate date with regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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