Created
January 25, 2017 22:11
-
-
Save carcus88/74628a94bc135a2c8957af7474c177d3 to your computer and use it in GitHub Desktop.
validate a date string in javascript
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
function isValidDate(date) { | |
var parts = date.split('/'); | |
var month = parts[0]; | |
var day = parts[1]; | |
var year = parts [2]; | |
year = Number(year); | |
month = Number(month); | |
day = Number(day) | |
var d = new Date(date); | |
if (d.getFullYear() != year | |
|| (d.getMonth() + 1) != month | |
|| d.getDate() != day) { | |
return false; | |
} | |
return true; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment