Last active
July 15, 2016 19:35
-
-
Save mir4ef/a9c9f7e50a739c60100cf643e759f4b7 to your computer and use it in GitHub Desktop.
RegExp to validate a date format in JS, but needs extra checks for leap years and 30 day months
This file contains hidden or 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
// date format: 'YYYY-MM-dd' | |
var RegExp = /^(199\\d)|([2-9]\\d{3})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])$/; | |
// date format: 'MM/dd/YYYY', | |
RegExp = /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/; | |
// passed as a string | |
var regexp = new RegExp('^(0[1-9]|1[0-2])\/(0[1-9]|1\\d|2\\d|3[01])\/(19|20)\\d{2}$'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment