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.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Nov 8, 2009, 12:41 AM
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 :)