這個簡單,用我的沒問題。可要給分哦。
以下用javascript寫的,經過調試。沒問題。
<%@ page contentType="text/html;charset=BIG5"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>New Page 2</title>
</head><body><input type=text onblur="checkDateInput(this);" value="2002.3.6"><br/><input type=text onblur="checkDateInput(this);" value="fdsaf"><br/>
<script> 
function checkDateInput(obj)  
{
if (obj.value.length==0) return false;
var objValue=obj.value.replace(/[-\.]/g,"/");
var a=new Date(objValue);
if (isNaN(a))
{
obj.value="";
alert("!!!!?注意:\n您剛才輸入的日期不正确");
obj.focus();
return false;
}
var b;
if (a.getFullYear()<1900||a.getFullYear()>2200)
{var Today=new Date();
b=Today.getFullYear()+"-"+(a.getMonth()+1)+"-"+a.getDate();
}
else if (a.getFullYear()<1930)
b=(a.getFullYear()+100)+"-"+(a.getMonth()+1)+"-"+a.getDate();
else b=a.getFullYear()+"-"+(a.getMonth()+1)+"-"+a.getDate();
obj.value=obj.value.replace(/[-\.\/]0*/g,"-");
if (b!=obj.value)
{
obj.value=b;
alert("!!!!?注意:\n您剛才輸入的日期不正确。");
obj.select();
obj.focus();
return false;
}
return true;
}
</script></body>
</html>