What's Here?
- Members: 300,326
- Replies: 825,562
- Topics: 137,373
- Snippets: 4,417
- Tutorials: 1,147
- Total Online: 1,973
- Members: 123
- Guests: 1,850
|
A method to allow the user to enter only certain specific characters into a text box and ignore any other key. In this example only numbers, the Backspace key and the period will be allowed, everything else is ignored.
|
Submitted By: Jayman
|
|
Rating:
 
|
|
Views: 21,049 |
Language: VB.NET
|
|
Last Modified: August 9, 2006 |
|
Instructions: Put this code inside the KeyPress event for any text box that you want to limit user input. |
Snippet
'allow only numbers, the Backspace key and the period
If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." Then
'cancel keys
e.Handled = True
End If
Copy & Paste
|
|
|
|