Click here to Skip to main content
16,018,973 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
please help me i have the texetbox this this text in databeas is number how i can make this text dont accebte the litter
Posted

Hi,
here is the code-
C#
protected override void OnKeyPress(KeyPressEventArgs e)

{

if ((!char.IsDigit(e.KeyChar)) && (e.KeyChar != 8))

    e.Handled = true;

}
 
Share this answer
 
As you have only tagges your question to C#, I am not sure if you want to do this in Windows or Web App.
In any case, I would use the regular expressions.
For start, you can use the following RegEx.
C#
Regex regex = new Regex("^[0-9]+$");

Read more about the Regex [^]class on MSDN.
 
Share this answer
 
Comments
VJ Reddy 10-Jun-12 20:08pm    
Good answer. 5!
Manas Bhardwaj 11-Jun-12 5:14am    
thx!
You have a couple options, as specified in this Stack Overflow question:

http://stackoverflow.com/questions/463299/how-do-i-make-a-textbox-that-only-accepts-numbers[^]
 
Share this answer
 
Comments
VJ Reddy 10-Jun-12 20:08pm    
Good answer. 5!

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