JSFiddle - React, Tailwind, and code Playground
by Shef
JavaScript
function isGoodDate(dt){
var reGoodDate = /^(?:(0[1-9]|1[012])[\/.](0[1-9]|[12][0-9]|3[01])[\/.](19|20)[0-9]{2})$/;
return reGoodDate.test(dt);
}
var first = '06/01/2011',
second = '1/3/2011',
third = '06-01-2011';
if(!isGoodDate(first)){
alert("First date not in correct format of MM/dd/YYYY");
}
if(!isGoodDate(second)){
alert("Second date not in correct format of MM/dd/YYYY");
}
if(!isGoodDate(third)){
alert("Third date not in correct format of MM/dd/YYYY");
}