September 24, 2015

How to make a TextBox accept only alphabetic characters?

 private void txtname_TextChanged(object sender, EventArgs e)
        {
            if (!System.Text.RegularExpressions.Regex.IsMatch(txtname.Text, "^[a-zA-Z]"))
            {
                MessageBox.Show("This textbox accepts only alphabetical characters");
                txtname.Text = "";
            }
        }

No comments:

Post a Comment