|
-
October 8th, 2006, 10:13 PM
#1
input validation
hello all,
Does anyone know a better way or function to retrict user input, for example special characters are not allow
thanks
-
October 8th, 2006, 11:17 PM
#2
Re: input validation
if u mean in textbox
have u try this ...
i validate a textbox in vb6 where user only can input character, space, and backspace.
u can customize it so that number is also valid for the textbox
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not ((KeyAscii > Asc("A") - 1 And KeyAscii < Asc("Z") + 1) _
Or (KeyAscii > Asc("a") - 1 And KeyAscii < Asc("z") - 1) _
Or KeyAscii = 32 Or KeyAscii = 8 _
) _
Then _
'32 is for space, 8 is for backspace
KeyAscii = vbKeyEscape
End If
End Sub
it works like this :
first u set the range of valid ascii ..
if the ascii of the string/char that u want to check is not in the valid range,
1. u can delete it,
2. u can pop a messagebox to remind user that it is not a valid input
with that code above, i change into vbKeyEscape, because the validation is processed on keypress even.
may this give an explanation
-
October 9th, 2006, 12:47 AM
#3
Re: input validation
ya, i get it already , thanks
-
October 9th, 2006, 01:24 AM
#4
Re: input validation
 Originally Posted by limck
hello all,
Does anyone know a better way or function to retrict user input, for example special characters are not allow
thanks
Is there any special reason for blocking the keys. If you are worried about the database queries failing because of these special characters then instead of blocking them, use Parameterized queries. Search the forum for simple code snippets on that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|