返回输入类型时间的错误消息

时间:2016-09-14 15:31:16

标签: javascript html validation time

这是我的html输入类型时间的代码部分,包括其验证

<tr><td height="50"><div class="headingbox" id="hBoxTime" >Expected Time </div>
            <div style="width:100%;text-align:center;">
            <input type="time" id=time  autofocus name=DPTime   onfocusout="upperCASE(this);validateTime(this, 'timeerror')" onfocus="show('timeerror2');" min="08:00:00" max="16:00:00" onblur="onTimeChange()" /><br>
            </div>

               <div class="error" id="timeerror" > error occured </div><br>
     <script>
var input =  document.getElementById('time');
function validateTime (element,errorCode) {

var minTime = element.min;
var maxTime = element.max
var value = element.value + ':00'
var notify = document.getElementById(errorCODE);
console.log(minTime,maxTime,value);
if(minTime > value ||  value > maxTime) {
  notify.innerHTML = "Enter between 8am and 4pm";
            element.style.border = "2px solid #ff6768";
            notify.style.opacity="1";
            timeValid = false;
            headingBoxAlert("hBoxTime", timeValid);
}

}



</script> 

这是输入类型电子邮件的html代码及其在Javascript中的验证代码

  <tr><td height="50"><div class="headingbox" id="hBoxEM"> E-mail </div>
                <div style="width:100%;text-align:center;">
                <input type="text"  autofocus name=Email onfocus="headingBoxActive('hBoxEM')" onfocusout="validateEmail(this, 'emailerror');"  /><br>
                </div>
                <div class="error" id="emailerror" > error occured </div><br>
<script>
                 function validateEmail(element, errorCODE){
        var str = element.value;
        var dotCount = 0;
        var atCount = 0;
        var notify = document.getElementById(errorCODE);
        if(str.length==0) {
            notify.innerHTML = "Email must be specified";
            element.style.border = "2px solid #ff6768";
            notify.style.opacity="1";
            emailValid = false;
            headingBoxAlert('hBoxEM', emailValid);
        }
        else if(str.length<6){
            notify.innerHTML = "Invalid email.";
            element.style.border = "2px solid #ff6768";
            notify.style.opacity="1";
            emailValid = true;
            headingBoxAlert('hBoxEM', emailValid);
        }
</script>

虽然电子邮件验证显示电子邮件错误,但如果我输入的值不是在上午8点到下午4点之间,则会显示错误,请帮助我纠正错误! enter image description here

0 个答案:

没有答案