I am looking to validate a field. It should only include alphanumeric characters (A-Z, a-z, and/or 0-9). Is there a string function in ASP (ver5) that will do this? If not, what is the simplest way to do this with regular expressions?
Do you know InStr function?
' tocheck is the string to be checked
validdata = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
for i = 1 to Len(tocheck)
if not InSTR(1, validdata, mid(tocheck, i, 1), 1) then
' wrong data
<code for wrong data>
end if
next
There is some basic code you can use to stop somone from even TYPEING IN anything but the characters you want them to. If you only want them to type 1-9, they won't be able to type A-Z or a-z. or if you want anything for A-Z, a-z, or 1-9, then you can do that too. Anything you want....here is what you do:
That is the syntax...now here are the values of what each number equals in value to that on the keyboard so you can edit it to block or accept whichever characters you wish:
----------------------------------
33 ! -Exclamation Mark
34 " -Quote
35 # -Pound sign
36 $ -Dollar Sign
37 % -Percent sign
38 & -ampersand
39 ' -apostrophe
40 ( -left parenthesee
41 ) -right parenthesee
42 * -assterik
43 + -plus sign
44 , -comma
45 - -dash
46 . -period
47 / -forward slash
-------------------------------------
48 0 -NUMBERS-
49 1
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
-------------------------------------------
58 : -colon
59 ; -semi-colon
60 < -less than sign
61 = -equal sign
62 > -greater than sign
63 ? -question mark
64 @ -AT sign
-----------------------------------------
65 A -ALL CAPITOL LETTERS-
66 B
67 C
68 D -ALL CAPITOL LETTERS-
69 E
70 F
71 G
72 H
73 I
74 J -ALL CAPITOL LETTERS-
75 K
76 L
77 M
78 N
79 O
80 P
81 Q -ALL CAPITOL LETTERS-
82 R
83 S
84 T
85 U
86 V -ALL CAPITOL LETTERS-
87 W
88 X
89 Y
90 Z -ALL CAPITOL LETTERS-
---------------------------------------
91 [ -left brace
92 \ -backward slash
93 ] -right brace
94 ^ -up arrow
95 _ -underscore
96 ` -little thing below the tilda
----------------------------------------
97 a -ALL SMALL LETTERS-
98 b
99 c
100 d
101 e -ALL SMALL LETTERS-
102 f
103 g
104 h
105 i
106 j
107 k -ALL SMALL LETTERS-
108 l
109 m
110 n
111 o
112 p -ALL SMALL LETTERS-
113 q
114 r
115 s
116 t
117 u
118 v -ALL SMALL LETTERS-
119 w
120 x
121 y
122 z -ALL SMALL LETTERS-
--------------------------------------
123 { -left bracket
124 | -pipe
125 } -right bracket
126 ~ -tilda
---------------------------------------
Now, as you can see above, you can use any arange ment by blocking or accepting groups of numbers which represent the input by the keyboard. so let's say you only wanted to allow capitol letters and numbers in field, no symbols, or small letters, here is what you'd type:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.