Textbox only contains numbers: 0 ~ 9
It is very simple to add a property event:
<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 receive only numbers: 0 ~ 9
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>
The following table lists the key value of event. keycode.
| Key value for letters and numbers) |
| Buttons |
Key code |
Buttons |
Key code |
Buttons |
Key code |
Buttons |
Key code |
|
A |
65 |
J |
74 |
S |
83 |
1 |
49 |
| B |
66 |
K |
75 |
T |
84 |
2 |
50 |
| C |
67 |
L |
76 |
U |
85 |
3 |
51 |
| D |
68 |
M |
77 |
V |
86 |
4 |
52 |
| E |
69 |
N |
78 |
W |
87 |
5 |
53 |
| F |
70 |
O |
79 |
X |
88 |
6 |
54 |
| G |
71 |
P |
80 |
Y |
89 |
7 |
55 |
| H |
72 |
Q |
81 |
Z |
90 |
8 |
56 |
| I |
73 |
R |
82 |
0 |
48 |
9 |
57 |
| Key |
Key code |
Buttons |
Key code |
Buttons |
Key code |
Buttons |
Key code |
|
0 |
96 |
8 |
104 |
F1 |
112 |
F7 |
118 |
| 1 |
97 |
9 |
105 |
F2 |
113 |
F8 |
119 |
| 2 |
98 |
* |
106 |
F3 |
114 |
F9 |
120 |
| 3 |
99 |
+ |
107 |
F4 |
115 |
F10 |
121 |
| 4 |
100 |
Enter |
108 |
F5 |
116 |
F11 |
122 |
| 5 |
101 |
- |
109 |
F6 |
117 |
F12 |
123 |
| 6 |
102 |
. |
110 |
|
|
|
|
| 7 |
103 |
/ |
111 |
|
|
|
|
| Key Value) |
| Buttons |
Key code |
Buttons |
Key code |
Buttons |
Key code |
Buttons |
Key code |
| Backspace |
8 |
ESC |
27 |
Right arrow |
39 |
-_ |
189 |
| Tab |
9 |
Spacebar |
32 |
Down Arrow |
40 |
.> |
190 |
| Clear |
12 |
Page up |
33 |
Insert |
45 |
/? |
191 |
| Enter |
13 |
Page down |
34 |
Delete |
46 |
'~ |
192 |
| Shift |
16 |
End |
35 |
Num Lock |
144 |
[{ |
219 |
| Control |
17 |
Home |
36 |
;: |
186 |
\ | |
220 |
| ALT |
18 |
Left arrow |
37 |
= + |
187 |
]} |
221 |
| Cape lock |
20 |
Up Arrow |
38 |
, < |
188 |
'" |
222 |