i want a text box which allow only letters numbers hyphen and back space
plz hlp
Textbox validation
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Hemant SrivastavaRank #581 · 4.2K reputationPosted Nov 12, 2013, 6:10 AM EST
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;
}
}