Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Numeric Only TextBox Control [duplicate]

I am using C#.NET 3.5, and I have a problem in my project. In C# Windows Application, I want to make a textbox to accept only numbers. If user try to enter characters message should be appear like "please enter numbers only", and in another textbox it has to accept valid email id message should appear when it is invalid. It has to show invalid user id.

like image 455
vamshi Avatar asked Feb 17 '11 12:02

vamshi


1 Answers

use this code:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            const char Delete = (char)8;
            e.Handled = !Char.IsDigit(e.KeyChar) && e.KeyChar != Delete;
        }
like image 151
jolly Avatar answered Oct 19 '22 04:10

jolly