• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VB.NET need to create a "letters only" input textbox

crumpet19

Platinum Member
This is part of a homework assignment for class and its driving me up a wall.
Using VB.NET I need to take an input textbox and using keypress I need to restrict the keys that the user can type to letters only -no special characters and no numbers.

If you have any ideas about this code, please let me know. I've been working on this for three hours now and i know I'm making it more difficult than it is.



Also, I'm kinda new to the whole programming thing.. so before you write an explanation completely in jargon.. try to dumb it down a little for me if you can please.


"Private Sub StateTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles StateTextBox.KeyPress
If e.KeyChar (something to restrict to letter chars only) Then
e.Handled = True


End If
End Sub"

thanks for any help you can give!
christopher
 
Get the ASCII value of the inputed character and makes sure the value falls in the ASCII letters range.

ASCII TABLE

the inputed character would have to fall between the values of 65 and 122 excluding 91-96
 
A neat trick is to use instr. I'm assuming the code that you wrote works as intended.

dim alpha as string = "abcdefghijklmnopqrstuvwxyz"

if instr(alpha,lcase(e.keychar)) then e.handled = true
 
Back
Top