0

how can i trap my textbox that allows numbers and letters only, no space no special characters e.g (,./;'[]-=`<>?:"{}_+|~!@#$%^&*())

2
Contributors
2
Replies
5
Views
4 Years
Discussion Span
Last Post by TnTinMN
0
   Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
      If Not Char.IsLetterOrDigit(e.KeyChar) Then
         e.Handled = True
      End If
   End Sub
0

Just thought about the decimal seperator.

   Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
      If (Not Char.IsLetterOrDigit(e.KeyChar)) And e.KeyChar <> Threading.Thread.CurrentThread.CurrentUICulture.NumberFormat.NumberDecimalSeparator Then
         e.Handled = True
      End If
   End Sub
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.