textbox, block special sql characters

ramone

Freshman
Joined
Sep 29, 2005
Messages
26
hello
how can i block users from entering special sql characters in textboxes, like # ' \ " and -- ?
i know it can be done with the keypress event of the textbox but i don't know how exactly

thank you
 
this here only allows numbers and the backspace keys to work in the textbox.
So hopefully this can send you in the right direction.
you can also get the decimal number for an individual key and use an expression down below with the sub I provided

Asc(e.KeyChar) = 47 ' this would be for "/"
Code:
 Private Sub txtMaxTrans_Keydown(ByVal sender As System.Object, ByVal e As KeyPressEventArgs) Handles txtMaxTrans.KeyPress
        If Not Char.IsNumber(e.KeyChar) And Not Asc(e.KeyChar) = Keys.Back Then
            e.Handled = True
        End If
End Sub
 
Back
Top