Validation help with text box

Steven Low

Active member
Joined
Apr 14, 2005
Messages
42
Programming Experience
1-3
Hi guys
The below validation only allows text no number input but i cant go back. What would i need to code to allow this:confused:


Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar.IsLetter(e.KeyChar) = False Then
e.Handled = True
End If
End Sub
 
Try this:

VB.NET:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress 
       If Not e.KeyChar.IsLetter(e.KeyChar) AndAlso  e.KeyChar <> ControlChars.Back
              e.Handled = True 
       End If 
     End Sub
 
or:
VB.NET:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress 
  If e.KeyChar.IsLetter(e.KeyChar) = False AndAlso  Asc(e.KeyChar) <> Keys.Back
         e.Handled = True 
  End If 
End Sub
 
Back
Top