<div class="htmlarea"> <textarea id="runcode19530"> <title>JavaScript 检查是否是正确的日期格式</title> <script language="javascript"> function check(){ str = form1.txt.value; str = str.match(/^(\d{2,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); if (str == null){ alert('你输入的日期格式无效'); return false; }else if (str[3]>12 || str[4]>31){ alert("你输入的日期格式无效"); return false }else{ alert("你输入的日期格式有效"); return true; } } </script> <form name="form1" onsubmit="return check()"> <input type="text" name="txt"> <input type="submit" value="检验"> </form> </textarea><br><input onclick="runEx('runcode19530')" type="button" value="运行代码"> <input onclick="doCopy('runcode19530')" type="button" value="复制代码"> <input onclick="doSave(runcode19530)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>