Date.prototype.toISOString
throws RangeError
(at least in Chromium and Firefox) on invalid dates. You can use it as a means of validation and may not need isValidDate
as such (EAFP). Otherwise it's:
function isValidDate(d)
{
try
{
d.toISOString();
return true;
}
catch(ex)
{
return false;
}
}