<script>
function isDate(str)
{
var d = new Date(str)
return !isNaN(d)
}
</script>
function isDate(str)
{
var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
result = str.match(reg);
if(result == null)return false;
var d = new Date(result[1],result[3]-1,result[4])
var newStr = d.getFullYear()+result[2]+(d.getMonth()+1)+result[2]+d.getDate();
return str == newStr
}
try
{
hdate=new Date(hyear,hmonth-1,day)
}
catch(e)
{
alert('错误');
}
<script language="JavaScript">
String.prototype.IsDate=function()
{
var str=this;
var reg =/^(\d+)-(\d{1,2})-(\d{1,2})$/;
var r=str.match(reg);
if(r==null)return false;
r[2]=r[2]-1;
var d=new Date(r[1],r[2],r[3]);
if(d.getFullYear()!=r[1])return false;
if(d.getMonth()!=r[2])return false;
if(d.getDate()!=r[3])return false;
return true;
}
</script>