in text box i restrict to type special characters. i want to type only characters.
how to validate please help me.
How to validate text box
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
Abdur RehmanRank #2,563 · 545 reputationPosted Mar 9, 2012, 2:57 AM EST
add this event to textbox this.txtBox.Validating += new System.ComponentModel.CancelEventHandler(this.numberBox_Validating); use this function to validate private void numberBox_Validating(object sender, CancelEventArgs e) { try { int numberEntered = int.Parse(numberBox.Text); if (numberEntered 10) { e.Cancel = true; MessageBox.Show("You have to enter a number between 1 and 10"); } } catch (FormatException) { e.Cancel = true; MessageBox.Show("You need to enter an integer"); } } the above code validates numbers, u can use ascii value to check for your range of specail characters