Of course, this should not be validation (which you can also use), but filtering out some of the input.
Please see my comment to the question: as you did not specify what exactly do you mean by "text box", it's impossible to give one exact answer. I can explain you the idea. Typically, you have to handle the text box's event
KeyPress
Event arguments of these class has some property to indicate that you cancel the event ("Handled"). Based on the the data passed to your event handler (a character attempted to enter), accept or deny it. It will give you exactly the effect you need.
Don't forget to allow for backspace. By some (historical?) reasons it is considered as a "character", code point 8.
[EDIT]
This case shows how bad was your failure to specify the full type name of the text box class you are using. I have to answer twice.
So, you handle this event:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress%28v=vs.110%29.aspx[
^].
And, to deny some of input, set to true this property of event arguments:
http://msdn.microsoft.com/en-us/library/system.windows.forms.keypresseventargs.handled%28v=vs.110%29.aspx[
^].
You could easily find it all by yourself, instead of complaining, especially after reading my part of the answer above. How your "not WPF" was relevant? I knew it could be not WPF, so what.
As to capturing the Paste operation, yes, this is a different story: the problem is a bit more difficult. First, you can always catch a raw Windows message
WM_PAST
. This is how:
http://www.experts-exchange.com/Programming/Languages/.NET/Q_24099882.html[
^].
Another solution would be capture the key combinations Ctrl+C and Shift+Ins and replace a context menu where the past operation might me:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.previewkeydown(v=vs.110).aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.contextmenu(v=vs.110).aspx[
^].
—SA