<body>
<input type="date" name="textfield" id="text1" >
<input type="button" value="按钮" onClick="checkDate('text1')">
</body>
js代码
function checkDate(fname){
var sc = $("#"+fname);
var s = sc.val();
if (sc==null){
alert("Element is null");
return true;
}
var reg=/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/;
if(!s.match(reg)){
alert("false");
}else{
alert("true"); }}
时间: 2024-09-23 14:48:08