<html>
<head>
<title>test</title>
<script>
function checktime(ctime)
{
if (ctime.length == 0) return true; var re=/^(([0-9]|[01][0-9]|2[0-3])(:([0-9]|[0-5][0-9])){0,2}|(0?[0-9]|1[0-1])(:([0-9]|[0-5][0-9])){0,2}\s?[aApP][mM])?$/;
alert(re.test(ctime));
}
</script></head>
<body>
<td width="11%"><input type="text" name="traffic06" onBlur="checktime(this.value)" size="11"></td>
</body>
</html>
<head>
<title>test</title>
<script>
function checktime(ctime)
{
if (ctime.length == 0) return true; var re=/^(([0-9]|[01][0-9]|2[0-3])(:([0-9]|[0-5][0-9])){0,2}|(0?[0-9]|1[0-1])(:([0-9]|[0-5][0-9])){0,2}\s?[aApP][mM])?$/;
alert(re.test(ctime));
}
</script></head>
<body>
<td width="11%"><input type="text" name="traffic06" onBlur="checktime(this.value)" size="11"></td>
</body>
</html>
<head>
<title>test</title>
<script>
function check(ctime)
{
var re=/^(([0-1][0-9])|(2[0-3])):([0-5][0-9])$/g;
alert(re.test(ctime));
}
</script></head>
<body>
<td width="11%"><input type="text" name="traffic06" onBlur="check(this.value)" size="11"></td>
</body>
</html>
<script>
function check(obj)
{
if (obj.value=="") return false;
var a=new Date('2001/1/1 '+obj.value+":");
if(isNaN(a))
{alert("请按以下格式输入时间:\n12:30");obj.focus();obj.select();return false;}
obj.value=a.getHours()+":"+a.getMinutes();
}
</script>
但是只有JK_10000(JK1)的程序能具有纠错能力!
可惜有BUG,就是在 13:00会变成 13:0
13:05成为 13:5
西西 要能完善就好了,谢谢各位帮忙,我晚上结帖子
<script>
function check(obj)
{
if (obj.value=="") return false;
var a=new Date('2001/1/1 '+obj.value+":");
if(isNaN(a))
{alert("请按以下格式输入时间:\n12:30");obj.focus();obj.select();return false;}
obj.value=(a.getHours()>9?a.getHours():"0"+a.getHours())+":"+(a.getMinutes()>9?a.getMinutes():"0"+a.getMinutes());
}
</script>