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>