Created
August 28, 2017 21:13
-
-
Save igorhasse/c83bd46ca46cdad8d275bc2a06adbf5d to your computer and use it in GitHub Desktop.
Validation Valid 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
// Expect input as d/m/y | |
function isValidDate(s) { | |
var bits = s.split('/'); | |
var d = new Date(bits[2], bits[1] - 1, bits[0]); | |
return d && (d.getMonth() + 1) == bits[1]; | |
} | |
['0/10/2017','29/2/2016'].forEach(function(s) { | |
console.log(s + ' : ' + isValidDate(s)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment