i want a text box which allow only letters numbers hyphen and back space
plz hlp
Loading
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.
Hemant SrivastavaPosted Nov 12, 2013, 11:10 AM
private void txtBx_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\b' // Allowing Back Space
||Char.IsLetterOrDigit(e.KeyChar) // Allowing any letter OR Digit
|| e.KeyChar == '-') // Allowing Hyphen
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}