kshadow22

Restrict Charracters From Textbox

Nov 14th, 2019
49
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Restrict a textbox to only specific charracters
  2.  
  3. Public Class MainForm
  4.  
  5.     Dim charactersAllowed As String = " abcdefghijklmnopqrstuvwxyz1234567890"
  6.  
  7.     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  8.         Dim theText As String = TextBox1.Text
  9.         Dim Letter As String
  10.         Dim SelectionIndex As Integer = TextBox1.SelectionStart
  11.         Dim Change As Integer
  12.  
  13.         For x As Integer = 0 To TextBox1.Text.Length - 1
  14.             Letter = TextBox1.Text.Substring(x, 1)
  15.             If charactersAllowed.Contains(Letter) = False Then
  16.                 theText = theText.Replace(Letter, String.Empty)
  17.                 Change = 1
  18.             End If
  19.         Next
  20.  
  21.         TextBox1.Text = theText
  22.         TextBox1.Select(SelectionIndex - Change, 0)
  23.     End Sub
  24.  
  25. End Class
  26.  
  27. youtube.com/kshadow22
RAW Paste Data