Saturday, December 17, 2011

How to validate a number between 0-24 with Java Scripts

<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <script language="javascript" type="text/javascript">
        function checkIt(obj, evt) {
            evt = (evt) ? evt : window.event
            var charCode = (evt.which) ? evt.which : evt.keyCode
            if ((charCode < 45 || charCode > 57) && charCode != 8 && charCode != 37 && charCode != 39) {
                alert("This field accepts numbers only")
                return false
            }
            var t = (charCode / 1) - 48;
            var v = obj.value + t;
            var value = v / 1;
            if(value > 24){ 
                alert("Number should be less than 24");
                return false;
            }
            return true
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox runat="server" ID="txtNumber" onKeyPress='javascript:return checkIt(this, event)' />
    </div>
    </form>
</body>
</html>

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...