0

I'm trying to create a form that has a text box that only accepts text entries (i.e. no numeric entries). I can't figure it out....this is what I have so far...

Private Sub textName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textName.TextChanged
        If textName.Text.Trim <> "" Then
            Try
                employeeName = Text
            Catch ex As Exception
                MessageBox.Show("Input Must Be Text Only", _
                     "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                textName.Focus()
                textName.SelectAll()
            End Try
        End If
    End Sub
End Class
2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by apegram
0

Maybe look into regular expressions. Example:

Sub Main()

        Dim rgx As New System.Text.RegularExpressions.Regex("^[a-zA-Z]+$")
        Console.WriteLine(rgx.IsMatch("ABC"))
        Console.WriteLine(rgx.IsMatch("A12"))
        Console.Read()


    End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.