How to enter only numbers in the input box, and only numbers in the input box

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.