Click here to Skip to main content
15,741,692 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
how can i restrict user from inputting special characters, letters and numbers in C#?
Toniyo Jackson 25-Nov-10 2:18am    
For winforms r web?

if ((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == 8 )
  e.Handled = false;
  e.Handled = true;

use ASCII Table for set that which key you want to be pressed and whichone not, this code can be used for enter only numeric data and allow the backspace .
Share this answer
Dalek Dave 25-Nov-10 4:41am    
Good Call
Have a look at this recent question and the answers. This should help you since a lot of alternatives are shown.

how shall i check the letter is a to z or A to Z[^]
Share this answer
Dalek Dave 25-Nov-10 4:42am    
Good link
sujeet101 2-Dec-10 5:13am    
good link

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900