JS验证时间格式
程序员文章站
2022-06-17 14:07:02
...
如果想看程序运行效果,请先点击阅读全文,然后再点击代码即可.
<script language="javascript">
<!--
function Checkform(form)
{
var rr=/^(?:19|20)[0-9][0-9]-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:[0-2][1-9])|(?:[1-3][0-1])) (?:(?:[0-2][0-3])|(?:[0-1][0-9])):[0-5][0-9]:[0-5][0-9]$/
if(!rr.test(form.date.value))
{
alert('请输入正确的时间格式,如:2005-01-27 22:12:00');
form.date.focus();
return false;
}
alert('ok!');
return true;
}
//-->
</script>
<form name="form1" method="post" action="" onSubmit="return Checkform(this);">
<input name="date" type="text" id="date" size="20" maxlength="19">
<input type="submit" name="Submit" value="提交">
</form>