How to restrict the user entering some invalide keys in TestBox
-
I am developing Login Control where the user can enter username and password. in the Username and password box i should restrict the user from entering Special Chars, and other invalid keys. i know i can compare the the value in Keydown event using Keys.Keycode, but it is very ugly to put all the Spl char comparision like if(e.Keycode==Keys.Enter || etc..). Is there any function or way to Compare the key pressed is a spl. char or not. Thanks and Regards Srini
-
I am developing Login Control where the user can enter username and password. in the Username and password box i should restrict the user from entering Special Chars, and other invalid keys. i know i can compare the the value in Keydown event using Keys.Keycode, but it is very ugly to put all the Spl char comparision like if(e.Keycode==Keys.Enter || etc..). Is there any function or way to Compare the key pressed is a spl. char or not. Thanks and Regards Srini
-
I am developing Login Control where the user can enter username and password. in the Username and password box i should restrict the user from entering Special Chars, and other invalid keys. i know i can compare the the value in Keydown event using Keys.Keycode, but it is very ugly to put all the Spl char comparision like if(e.Keycode==Keys.Enter || etc..). Is there any function or way to Compare the key pressed is a spl. char or not. Thanks and Regards Srini
Think outside the box!!!!! You have a group of keys that you want to have disallowed from entry in a textbox. So a simple solution to this would be something like this:
List invalidKeys = new List(); ... private void ThisForm\_Load() { invalidKeys.Add(Keys.Enter); invalidKeys.Add(Keys.Ctl); ... } ... // keypress event handler if ( invalidKeys.Contains(e.Keycode) ) e.Handled = true;
-- modified at 9:49 Thursday 13th July, 2006