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="" >
<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;
         return true;
    <form id="form1" runat="server">
   <asp:TextBox ID="txt_maxage" Onkeypress="return isNumberKey(event)" runat="server"></asp:TextBox>

No comments:

Post a Comment

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

back to top