Я видел потенциальный ответ здесь, но это было для YYYY-MM-DD: проверка даты JavaScript
Я изменил приведенный выше код для MM-DD-YYYY, но я все еще не могу заставить его работать:
String.prototype.isValidDate = function()
{
var IsoDateRe = new RegExp("^([0-9]{2})-([0-9]{2})-([0-9]{4})$");
var matches = IsoDateRe.exec(this);
if (!matches) return false;
var composedDate = new Date(matches[3], (matches[1] - 1), matches[2]);
return ((composedDate.getMonth() == (matches[1] - 1)) &&
(composedDate.getDate() == matches[2]) &&
(composedDate.getFullYear() == matches[3]));
}
Как заставить приведенный выше код работать для MM-DD-YYYY, а еще лучше для MM/DD/YYYY?
Благодарю.