September 22, 2015

How to make a TextBox accept only Numeric values ?

private void txtEmpCode_TextChanged_1(object sender, EventArgs e)
        {
            if (System.Text.RegularExpressions.Regex.IsMatch(txtEmpCode.Text, "[^0-9]"))
            {
                MessageBox.Show("Please enter only numbers.");
                txtEmpCode.Text.Remove(txtEmpCode.Text.Length - 1);
                txtEmpCode.Text = "";
            }
        }

No comments:

Post a Comment