Last active
March 9, 2017 23:07
-
-
Save matthewnitschke/136419dd7a017c7832a8786ed649f86a to your computer and use it in GitHub Desktop.
IE happy date check
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
| function validDate(date){ | |
| var re = /(.{2})\/(.{2})\/((.{4})|(.{2}))/; | |
| if (date.search(re) == -1){ | |
| return false; | |
| } | |
| var dt = date.split("/"); | |
| // month must be less than 13, greater than 0 | |
| var month = dt[0]; | |
| if (parseInt(month) > 12 || parseInt(month) < 1) { | |
| return false; | |
| } | |
| var year = dt[2]; | |
| // day must be 2 digits, less than that months days, and greater than 0 | |
| var day = dt[1]; | |
| var daysInMonth = new Date(year, month, 0).getDate(); | |
| if (parseInt(day) > daysInMonth || parseInt(day) < 1){ | |
| return false; | |
| } | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment