How to enter only numbers in the input box, and only numbers in the input box
I haven't written a blog for a long time. I saw a blog post about how to write only numbers in a textbox using js.
The following describes how to implement it. First, create an empty web program on the web.
2. Right-click to add a web form: 3 and write js in the obtained page (remember to drag a textbox from the Toolbox) write a js method to get the ASII code of the letter you entered. If you enter a number, true is returned; otherwise, flase is returned; <% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "WebForm1.aspx. cs "Inherits =" WebApplication6.WebForm1 "%> <! DOCTYPE html> <% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "WebForm1.aspx. cs" Inherits = "WebApplication6.WebForm1" %>
<! DOCTYPE html>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> </title>
<Script type = "text/javascript">
Function ValidNumeric (){
Var charCode = (event. which )? Event. which: event. keyCode;
If (charCode> 47 & charCode <58)
{
Return true;
} Else {
Return false;
}
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
</Div>
LoginID <asp: TextBox ID = "LoginID" runat = "server" onkeypress = "return ValidNumeric ()"> </asp: TextBox>
</Form>
</Body>
</Html>
Then you can see the results,
A simple example.