Question

I want to filter the keyboard inputs into textbox based on the type of input I allow. e.g.

0 for Digits only 1 for Alphabets only 2 for Alphanumerics

So if 0 is configured and a character 'a' is pressed on the keyboard, it is not shown in the textbox. How do I do that in C#?

Thanks

Was it helpful?

Solution

You need to subscribe to control's KeyPress event (and optionally KeyDown method), and if key stroke must be eaten set Handled property to true. Read more in msdn (with sample that cover your problem).

OTHER TIPS

Not sure I understood your question correctly but you can use masked text box for creating many types of input filters.

you can use regular expressions. according to the user input you get, you can change your regular expression/validation method. below is an article that explains how to extend a textbox to validate against regular expressions. hope that helps at least to have some idea. http://www.c-sharpcorner.com/UploadFile/scottlysle/RegExTextBox01022007150131PM/RegExTextBox.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top