Thursday, December 15, 2011

Allowing only LETTERS in a textbox

Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress

If Asc(e.KeyChar) < 65 Or Asc(e.KeyChar) > 90 AndAlso Asc(e.KeyChar) < 97 Or Asc(e.KeyChar) > 122 Then

MessageBox.Show("Only Letters")

e.Handled = True

ElseIf Asc(e.KeyChar) = 8 Then
e.Handled = False

End If
End Sub

No comments:

Post a Comment