Created
November 15, 2019 04:27
-
-
Save fadziljusri/0ff43df3cdf7b72b7756234354ca4fe1 to your computer and use it in GitHub Desktop.
Date format validation
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
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