Saturday, 16 February 2013

Allow Only Numbers in Textbox Using Javascript - II [Cross Browser Compatible]

Allow Only Numbers in Textbox Using Javascript -II [Cross Browser Compatible]


I have already written a similar Post related to the above requirement over here:


So Here I am with another method with Alert Functionality and which is Cross Browser Compatible:


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Allow Only Numbers</title>
    
   <SCRIPT language=Javascript>
      <!--
      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
         {
            alert("Please Enter Only Numbers!");
            return false;
         }
         else
         {
         return true;
         }
      }
      //-->
   </SCRIPT>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
   <asp:TextBox ID="txt_maxage" Onkeypress="return isNumberKey(event)" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>

No comments:

Post a Comment

Thank You for Your Comments. We will get back to you soon.

back to top