What is code for validate the text box in vb.net for windows application?
i want accept only strings in my textbox if user enter any numbers in my textbox it will show error message...what is the code this task? plz send code...
What is code for validate the text box in vb.net for windows application?
i want accept only strings in my textbox if user enter any numbers in my textbox it will show error message...what is the code this task? plz send code...
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AlanPosted Aug 22, 2007, 6:42 AM
This code will prevent any numeric characters being input to a TextBox (textBox1 say) in the first place:
Private Sub textBox1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles textBox1.KeyPress
Dim key As Integer = CInt(e.KeyChar)
'disallow 0 to 9
If key >= 48 AndAlso key <= 57 Then
e.Handled = True
End If
End Sub
However, it won't stop numbers which are pasted in by the user. You can deal with that by setting the TextBox's ShortcutsEnabled property to False though this has the unwelcome side effects of preventing valid input being pasted in, or anything being copied, cut or deleted via the shortcut menu.