Asp.net how to verify that the textbox control only enters numbers (five situations analysis) Post

Source: Internet
Author: User

In Asp.net development, in order to ensure the correctness of the data, users are often limited to input content. The verification technique provided in this article is to ensure that the textbox control only inputs numbers, the details are further divided into five parts for your reference! The details are as follows:

First, add a property event to the Textbox Control:

<Asp: textbox class = "text"
Onkeypress = "If (event. keycode <48 | event. keycode> 57) event. returnvalue = false ;"
Id = "txty_revenue" style = "text-align: Right" runat = "server" width = "90%" maxlength = "12">
</ASP: textbox>

Note: This method controls textbox to only input numbers: 0 ~ 9. Provide an idea
Supplement:

1. The dotted box when the cancel button is pressed

Add the attribute value hidefocus or hidefocus = true in input.

2. Read-only text box content

Add the attribute value readonly in input.

3. Prevent text files from being cleared (style content can be referenced as a class)

<Input style = behavior: URL (# default # savehistory); type = text id = opersistinput>

4. Press enter to move the cursor to the next input box.

<Input onkeydown = "If (event. keycode = 13) event. keycode = 9">

5. It can only be Chinese (with flashing)

<Input onkeyup = "value = value. Replace (/[-~] /G, '')" onkeydown = "If (event. keycode = 13) event. keycode = 9">

6. Only numbers are allowed (with flashing)

<Input onkeyup = "value = value. replace (/[^ \ D]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ D]/g, '')">

7. Only numbers are allowed (no flashing)

<Input style = "ime-mode: Disabled" onkeydown = "If (event. keycode = 13) event. keycode = 9 "onkeypress =" If (event. keycode <48 | event. keycode> 57) event. returnvalue = false ">

8. Only English and numbers can be entered (with flashing)

<Input onkeyup = "value = value. replace (/[\ W]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ D]/g, '')">

9. shielded Input Method

<Input type = "text" name = "url" style = "ime-mode: Disabled" onkeydown = "If (event. keycode = 13) event. keycode = 9">

10. You can only enter numbers, decimal points, minus (-) characters (no flashing)

<Input onkeypress = "If (event. keycode! = 46 & event. keycode! = 45 & (event. keycode <48 | event. keycode> 57) event. returnvalue = false ">

11. Only two decimal places can be entered, and three decimal places (with flashing)

<Input maxlength = 9 onkeyup = "If (value. match (/^ \ D {3} $/) value = value. replace (value, parseint (value/10); value = value. replace (/\. \ D *\. /g ,'. ') "onkeypress =" If (event. keycode <48 | event. keycode> 57) & event. keycode! = 46 & event. keycode! = 45 | value. match (/^ \ D {3 }$/) | /\. \ D {3} $ /. test (value) {event. returnvalue = false} "id = text_kfxe name = text_kfxe>

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.