VB.NET 2010 - A way to prevent certain characters from being copy pasted inside of a textbox?
Posted on 2011-02-21
I have a simple method to prevent keypresses:
If (e.KeyChar < "0" OrElse e.KeyChar > "9") Then
e.Handled = True
Which goes in the keypress area. This will allow only 0 to 9 to be added. However, it seems like you can copy paste other characters inside the text box. I know I can do things such as looping through each character each time the text is changed, but this seems like it would be a not a very efficient way of handling this issue. Pretty much the goal here is to always make sure the characters 0 to 9 are allowed, while still keeping functions like PASTING in tact without having it disabled completely.
This can go for a-Z, etc. Thanks!