|
-
Feb 17th, 2009, 12:28 PM
#1
Thread Starter
Fanatic Member
Keypress Character Validation...Code Cleanup Help
I know that this is not the best way of doing this, so I am looking for suggestions for cleaning this up. Currently, it only allows the user to enter Alpha characters, spaces, and press the enter and backspace key in a textbox.
Code:
'allow alpha characters, spacebar and backspace key only
If (e.KeyChar < "A" OrElse e.KeyChar > "z") _
AndAlso e.KeyChar <> ControlChars.Back AndAlso Asc(e.KeyChar) <> Keys.Enter AndAlso Asc(e.KeyChar) <> Keys.Space Then
'Display error message
MessageBox.Show("Only alphabetic characters are allowed in this field.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
txtLastname.Focus()
e.Handled = True
End If
I need to write something to allow the following keys only:
Alpha keys, "Enter" key, "Backspace" key, "period" key, "ampersand", "spacebar" key, "apostrope" key, and "hypen" key
I want to make sure I am doing this with manage code. Thanks for any assistance.
-Jeremy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|