Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Restrict a textbox to only specific charracters
- 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
- youtube.com/kshadow22
Add Comment
Please, Sign In to add comment