In this post I will teach you about the Number and letter character allow only in textbox of vb.net it is very easy task you just need three text box from tool box after that use the below coding as per video instruction.

Public Class Form1 ReadOnly ValidChars As String = _ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ," Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If Char.IsNumber(e.KeyChar) Then Else MessageBox.Show("Invalid Input! Numbers Allow Only.", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error) e.Handled = True End If End Sub Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress If Not Char.IsLetter(e.KeyChar) Then If Char.IsLetter(e.KeyChar) Then Else MessageBox.Show("Invalid Input! Letter Allow Only.", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error) e.Handled = True End If End If End Sub Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress e.Handled = Not (ValidChars.IndexOf(e.KeyChar) > -1 _ OrElse e.KeyChar = Convert.ToChar(Keys.Back)) End Sub End Class
 
Top