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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
AlanRank #669 · 3.6K reputationPosted Aug 22, 2007, 2:42 AM EDT
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.