我想验证Time-Start和Time-End。时间格式就像这样2:15:00 AM我想确保Time-End必须大于或等于Time-Start。
Time-Start从DropDownListHourStart(1-12)和DropDownListMinuteStart(1-59)以及DropDownListSecondStart(00)和DropDownListAMPMStart(AM-PM)获取时间
Time-End从DropDownListHourEnd(1-12)和DropDownListMinuteEnd(1-59)以及DropDownListSecondEnd(00)和DropDownListAMPMEnd(AM-PM)获取时间
我想检查时间是否等于或大于时间输入。你能告诉我任何时间验证技术吗?无论是jQuery,JavaScript还是ASP.NET控件验证器。谢谢。
答案 0 :(得分:0)
假设日期相同:
function timeToSec(str)
{
var h = Number(str.match(/^\d+/));
if(str.indexOf("PM") != -1)
h += 12;
var m = Number(str.match(/^\d+:(\d+):/)[1]);
var s = Number(str.match(/:(\d+)\s+[AP]M/)[1]);
return (h * 60 + m) * 60 + s;
}
if(timeToSec(start) > timeToSec(end))
alert("Oops");
答案 1 :(得分:0)
<script type="text/javascript" >
var j = document.getElementById('DropDownListHourStart').value+":"+document.getElementById('DropDownListMinuteStart').value+":"+document.getElementById('DropDownListSecondStart').value+" "+document.getElementById('DropDownListAMPMStart').value;
var d = document.getElementById('DropDownListHourEnd').value+":"+document.getElementById('DropDownListMinuteEnd').value+":"+document.getElementById('DropDownListSecondEnd').value+" "+document.getElementById('DropDownListAMPMEnd').value;
if (d >= j) {
document.getElementById('your_label_id').innerText = "the Time-End must be greater or equal to the Time-Start";
}
</script>