Created
July 28, 2011 16:32
-
-
Save cowboy/1111886 to your computer and use it in GitHub Desktop.
JavaScript: Return date, if valid.
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 dateIfValid(y, m, d) { | |
| var date = new Date(y, --m, d); | |
| return !isNaN(+date) && date.getFullYear() == y && date.getMonth() == m && date.getDate() == d && date; | |
| } |
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 dateIfValid(y,m,d){var _=new Date(y,--m,d);return!isNaN(+_)&&_.getFullYear()==y&&_.getMonth()==m&&_.getDate()==d&&_} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know the regexp could be mucked with, but you could do smth like below to reduce the
day+yearcheck.golf'ed to