Problem with textbox
how to find the content of text box is a string or integer,that is my text box should accept only alphabets but no numerical values, if a user tries to enter the numerical values it should throw an exception.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Kirtan PatelRank #292 · 8.6K reputationPosted Nov 7, 2009, 7:41 PM EST
in KeyPress event of Text Box Write Code like Below
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
Regex rex = new Regex("[a-zA-Z ]");
if(rex.IsMatch(e.KeyChar.ToString()) == true || e.KeyChar == (char)Keys.Back || e.KeyChar == (char)Keys.Delete)
{
e.Handled = false;
}
else
{
e.Handled = true;
MessageBox.Show("you can not Enter Numbers or Sysmbols");
}
}
if my answer helps you then mark "Do you like this answer" check box :)