Wednesday, 15 October 2014

To check time entered is less than 24 hours and 60 minutes

No comments

Javascript

 function ChkTimeUp(txt) {

            var str = document.getElementById(txt).value;
            if (str.length == 2) {
                if (str > 24) {
                    alert("Hour Must be less than 24.")
                    document.getElementById(txt).value = "";
                }
                else {
                    str = str + ".";
                    document.getElementById(txt).value = str;
                }

            }
            else if (str.length == 5) {
                if (str.substring(3, 5) >= 60) {
                    alert("Minute Must be less than 60")
                    document.getElementById(txt).value = str.substring(0, 3);
                }
            }
            else if (str.length >= 5) {
                alert("Only Two Characters allowed After Decimal. ")
                document.getElementById(txt).value = str.substring(0, 3);
            }
        }


ASPX

  <asp:TextBox ID="txtInTime" Width="90%" CssClass="formTextBox" onkeyup="ChkTimeUp(this.id)"  onkeypress="return ChkPress(this.id,event)" runat="server"></asp:TextBox>