I m'looking for someone who may help concerning how to restrict textbox whether by letters, numbers or specials characters.
I got some cods that used to restrict Text box bellow:
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not Char.IsLetterOrDigit(e.KeyChar) Then
e.Handled = True
they are working with keyPress but not working with text-change, so I need that work with text change that can provide a message when wrong input is entered. I continued doing my research I reached to the following code, but I did not know how I can change them so that they can work for numbers and also how they can work with special character, please help me out. the codes were these bellow
Public Class MainForm
Dim charactersDisallowed As String = "1234567890"
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
For x As Integer = 0 To TextBox1.Text.Length - 1
Letter = TextBox1.Text.Substring(x, 1)
If charactersDisallowed.Contains(Letter) Then
theText = theText.Replace(Letter, String.Empty)
TextBox1.Text = theText
I want to know how I can apply them for numbers allowance and special characters allowance.