Skip to content

Instantly share code, notes, and snippets.

@UVLabs
Created July 28, 2015 17:17
Show Gist options
  • Save UVLabs/8afd151d2b00e23c3975 to your computer and use it in GitHub Desktop.
Save UVLabs/8afd151d2b00e23c3975 to your computer and use it in GitHub Desktop.
Public Class MainForm
Dim charactersAllowed As String = " abcdefghijklmnopqrstuvwxyz1234567890"
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim theText As String = TextBox1.Text
Dim Letter As String
Dim SelectionIndex As Integer = TextBox1.SelectionStart
Dim Change As Integer
For x As Integer = 0 To TextBox1.Text.Length - 1
Letter = TextBox1.Text.Substring(x, 1)
If charactersAllowed.Contains(Letter) = False Then
theText = theText.Replace(Letter, String.Empty)
Change = 1
End If
Next
TextBox1.Text = theText
TextBox1.Select(SelectionIndex - Change, 0)
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment