Skip to content

Instantly share code, notes, and snippets.

@fadziljusri
Created November 15, 2019 04:27
Show Gist options
  • Save fadziljusri/0ff43df3cdf7b72b7756234354ca4fe1 to your computer and use it in GitHub Desktop.
Save fadziljusri/0ff43df3cdf7b72b7756234354ca4fe1 to your computer and use it in GitHub Desktop.
Date format validation
String.prototype.isDate = function () {
// let format = /^((0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2})*$/; // MM/DD/YYYY
let format = /([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/; // YYYY-MM-DD
return (format.test(this))
? new Date(this).toISOString() === this
: false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment