I'm working on a custom textbox control that can "filter" out inappropriate input.

The filter property can be:


None would function like a normal textbox
Numerical would be any number key (1,2,3...)
LowerAlpha would be any alphabet character as long as it is lower cased
UpperAlpha would be any alphabet character as long as it is upper cased
Alpha is any alphabet character (case is ignored)
AlphaNumeric is any alphabet or number key
Symbol would be any symbol key (;,.'/?*&%!` etc...)

My question is, instead of on the KeyDown event checking which key was pressed by having if/then ad nauseum statements is there a system defined function or something to check these a bit better?

My check to see if a key was an integer is:

if (RestrictBy == Restrictions.Alpha)
                    if (e.KeyCode > Keys.D0 || e.KeyCode < Keys.D9)
                        if (e.KeyCode > Keys.NumPad0 || e.KeyCode < Keys.NumPad9)


I mean this is just getting out of control! An if statement for determining if a key was a alphabet or symbol key would be huge! There has to be a better way...or am I stuck?

Use char type method.

1. char.IsDigit
2. char.isLower and many more.

commented: Works perfectly! +5