How to set textbox take only numeric using java script.

In this article, we can set textbox contain only digit. Many times we have needed to set that textbox only take numeric value like bank account number, age and sku number, salary  and so on.



Design:-


Source Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="numberonlytextbox.aspx.cs" Inherits="numberonlytextbox" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title> How to set textbox take only numberic</title>
      <script type="text/javascript">
          function IsNumber(evt) {
              evt = (evt) ? evt : window.event;
              var charCode = (evt.which) ? evt.which : evt.keyCode;
              if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                  return false;
              }
              return true;
          }
   
    </script>
</head>
<body>
    <form id="form1" runat="server">
  <asp:TextBox ID="TextBox1" runat="server" onkeypress="return IsNumber(event)"
                placeholder=" Please Enter Only Digit">
    </asp:TextBox>
    </form>
</body>
</html>


Out-Put:-



How to set textbox take only numeric using java script. How to set textbox take only numeric using java script. Reviewed by NEERAJ SRIVASTAVA on 9:40:00 AM Rating: 5

No comments:

Powered by Blogger.