Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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 "/"

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

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...