.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> Validations >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Restrict User to write any digit words in Textbox

Posted By:Ravi Ranjan Kumar       Posted Date: June 29, 2011    Points: 40    Category: Validations    URL: http://www.dotnetspark.com  

This Code Snippets enable you to learn how to restrict user to type any digit words in TextBox

Take a textbox control on your Form and after that at at keypress event of textbox we can write given code to restrict user to write any single digit word 
 private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            // Restrict user to Enter Digit in texbox 
            if (char.IsDigit(e.KeyChar))
                e.Handled = true;
Alternative way

if ((e.KeyChar >= '0' && e.KeyChar <= '9'))
                e.Handled = true;


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend