Text box validation
-
How do i restrict user from entering any alpahabet or special characters in my textbox, in the textbox key press event. I need to give a error message and no alphabets or special charaters should get printed.(in visual C#).its a window form.
I'm not sure which characters you wish restricting. I'm assuming you're saying you only want numeric keypresses here. In the keypress event, you add the following code:
if (!char.IsDigit(e.KeyChar)) e.Handled = true;
If you want to display an error message, you should use the error provider component and set its text at the same point that you set the e.Handled flag.
Deja View - the feeling that you've seen this post before.
-
I'm not sure which characters you wish restricting. I'm assuming you're saying you only want numeric keypresses here. In the keypress event, you add the following code:
if (!char.IsDigit(e.KeyChar)) e.Handled = true;
If you want to display an error message, you should use the error provider component and set its text at the same point that you set the e.Handled flag.
Deja View - the feeling that you've seen this post before.