<html>
<body>
<form>
startTime:
<input type="text" id = "firstname" name="firstname">
<br />
endTime:
<input type="text" name="lastname">
<input type="button" name="onclick" value = "onclick" onclick = "testTime()">
</form>
</body>
<script>
function testTime()
{
var strTime1 = document.getElementById("firstname").value;
var endTime1 = document.getElementById("lastname").value;
var result1 = isTime(strTime1);
var result2 = isTime(endTime1);
if(result1 && result2)
{
var a = strTime1.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
var endTime = endTime1.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
var tmpStr = a[1] + a[3] + a[4];
var endTimeStr = endTime[1] + endTime[3] + endTime[4];
alert("tmpStr="+tmpStr);
alert("endTimeStr="+endTimeStr);
if(Number(endTimeStr) < Number(tmpStr))
{
alert("end time must later than start time!");
}
}
}
// 添加时间: 2005-07-11
//短时间,形如 (13:04:06)
function isTime(str)
{
var a = str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
if (a == null)
{
alert('输入的时间格式不正确');
return false;
}
/*
alert("a[1]="+a[1]);
alert("a[2]="+a[2]);
alert("a[3]="+a[3]);
alert("a[4]="+a[4]);
*/
if (a[1]>=24 || a[3]>=60 || a[4]>=60)
{
alert("时间格式不对");
return false
}
return true;
}
//***************************************************
</script>
</html>
<body>
<form>
startTime:
<input type="text" id = "firstname" name="firstname">
<br />
endTime:
<input type="text" name="lastname">
<input type="button" name="onclick" value = "onclick" onclick = "testTime()">
</form>
</body>
<script>
function testTime()
{
var strTime1 = document.getElementById("firstname").value;
var endTime1 = document.getElementById("lastname").value;
var result1 = isTime(strTime1);
var result2 = isTime(endTime1);
if(result1 && result2)
{
var a = strTime1.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
var endTime = endTime1.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
var tmpStr = a[1] + a[3] + a[4];
var endTimeStr = endTime[1] + endTime[3] + endTime[4];
alert("tmpStr="+tmpStr);
alert("endTimeStr="+endTimeStr);
if(Number(endTimeStr) < Number(tmpStr))
{
alert("end time must later than start time!");
}
}
}
// 添加时间: 2005-07-11
//短时间,形如 (13:04:06)
function isTime(str)
{
var a = str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
if (a == null)
{
alert('输入的时间格式不正确');
return false;
}
/*
alert("a[1]="+a[1]);
alert("a[2]="+a[2]);
alert("a[3]="+a[3]);
alert("a[4]="+a[4]);
*/
if (a[1]>=24 || a[3]>=60 || a[4]>=60)
{
alert("时间格式不对");
return false
}
return true;
}
//***************************************************
</script>
</html>