Lijina Lijina - 1 year ago 111
C# Question

How to make a TextBox accept only alphabetic characters?

How can I make a

only accept alphabetic characters?

Answer Source

You could use the following snippet:

private void textBox1_TextChanged(object sender, EventArgs e)
    if (!System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, "^[a-zA-Z]"))
        MessageBox.Show("This textbox accepts only alphabetical characters");
        textBox1.Text.Remove(textBox1.Text.Length - 1);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download