Skip to content

Instantly share code, notes, and snippets.

@zoubin
Created June 29, 2016 10:40
Show Gist options
  • Save zoubin/cc6d3deb48bb73237168c13269aa3ae0 to your computer and use it in GitHub Desktop.
Save zoubin/cc6d3deb48bb73237168c13269aa3ae0 to your computer and use it in GitHub Desktop.
Check if a given date string specifies a valid date
// http://jsbin.com/lamakud/edit?html,output
function isValidateDate(datestr) {
var ms = Date.parse(datestr)
if (isNaN(ms)) return false
return ~~(datestr.split(/[^d]/).pop()) === new Date(ms).getDate()
}
module.exports = isValidateDate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment