I came up with this:
function isValidDate(inputDate){
var myRegex = /^(\d{1,2})([\-\/])(\d{1,2})\2(\d{4}|\d{2})$/;
var match = myRegex.exec(inputDate);
if (match != null) {
var auxDay = match[1];
var auxMonth = match[3] - 1;
var auxYear = match[4];
auxYear = auxYear.length < 3 ? (auxYear < 70 ? '20' + auxYear : '19' + auxYear) : auxYear;
var testingDate = new Date(auxYear,auxMonth,auxDay);
return ((auxDay == testingDate.getDate()) && (auxMonth == testingDate.getMonth()) && (auxYear == testingDate.getFullYear()));
} else return false;
}
Works for dd-mm-yyyy
, dd-mm-yy
, d-m-yyyy
and d-m-yy
, using -
or /
as separators
Based on This script