TextBox Validation
Hi all i would like to validate a text box so that it should allow only numbers from 0-9 and A-Z(In capitals). Can any one tell how to do this
3 Answers
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
PJ MartinsRank #2,548 · 548 reputationPosted Jun 17, 2010, 7:17 AM EDT
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!System.Text.RegularExpressions.Regex.Match(e.KeyChar.ToString(), "[A-Z|0-9]").Success)
e.Handled = true;
}
Dorababu MekaRank #457 · 5.5K reputationPosted Jun 17, 2010, 10:05 AM EDT
PJ MartinsRank #2,548 · 548 reputationPosted Jun 17, 2010, 12:55 PM EDT