// KeyPress event
Private void txtAge_KeyPress (object sender, KeyPressEventArgs e)
{
// 48-57 is ASCII code 0-9, and 8 is the return key
If (e. KeyChar <48 | e. KeyChar> 57) & e. KeyChar! = 8)
{
E. Handled = true;
}
}
ASCII (US Information Exchange Standard Code) Table
Character
ASCII code
Character
ASCII code
Character
ASCII code
Binary
Decimal
Hexadecimal
Binary
Decimal
Hexadecimal
Binary
Decimal
Hexadecimal
Enter
ESC
Space
!
"
#
$
0001101
0011011
0100000
0100001
0100010
0100011
0100100
13
27
32
33
34
35
36
0D
1B
20
21
22
23
24
?
@
A
B
C
D
E
0111111
1000000
1000001
1000010
1000011
1000100
1000101 63
64
65
66
67
68
69 3F
40
41
42
43
44
45
B
C
D
E
F
G 1100001
1100010
1100011
1100100
1100101
1100110
1100111 97
98
99
100
101
102
103 61
62
63
64
65
66
67
%
&
,
(
)
*
+
0100101
0100110
0100111
0101000
0101001
0101010
0101011
37
38
39
40
41
42
43
25
26
27
28
29
2A
2B F
G
H
I
J
K
L 1000110
1000111
1001000
1001001
1001010
1001011
1001100 70
71
72
73
74
75
76 46
47
48
49
4A
4B
4C h
I
J
K
L
M
N 1101000
1101001
1101010
1101011
1101100
1101101
1101110 104
105
106
107
108
109
110 68
69
6A
6B
6C
6D
6E
,
-
.
/
0
1
2