JS簡單驗證時間格式


<body>
<script>
function checkdate() {
var datetype = /^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-2][0-4]:[0-5][0-9]:[0-5][0-9]$/;
var datetype1 = /^[0-9]{4}\/[0-9]{1,2}\/[0-9]{1,2}$/;
if (!(datetype.exec(document.form1.inputdate.value) || datetype1
.exec(document.form1.inputdate.value))) {
alert("sorry:2005-5-5 00:00:00or2005/1/1");
form1.inputdate.focus();
return false;
}
return true;
}
</script>
<form action="" name="form1">
輸入日期:<input type="text" name="inputdate"> <input type="button"
onClick="return checkdate();">
</form>
</body>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM