Textbox to accept only numbers in c# windows forms OR How to create a Numeric only Textbox?

A TextBox control is used to display, or accept as input, a single line or multiline of text. In many situations you need to enter only numeric only values in the Textbox. Here you can see some useful techniques that accept only numbers in the textbox.

You can make the textbox to accept the number only 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (Numeric) or backspace as input. Not using regular expressions.

private void Txtxmax_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(Char.IsDigit(e.KeyChar) || (e.KeyChar == (char)Keys.Back)))
                e.Handled = true;
        }

Need Help? Contact Us.

Log in

*
*

Forgot password?

*

New User

*
*
*
*