Click here to Skip to main content
15,911,360 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in textbox wont allow to type Numbers Only allow Characters using csharp in windows applciation.


Name textbox.

In the above textbox i wont allow to type Numbers Only allow Characters.

for that how to validate.

suppose when user type the Numbers in the textbox, want to show the message "Numbers not Allowed".
before saving the record in to record, show the popup message.

for that how can i do using csharp. please help me.

Thanks & regards,
Narasiman P.
Posted

Hi
C#
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
   if (!char.IsLetter(e.KeyChar))
   {
      e.Handled = false;
   }
}



Regards
Jegan
 
Share this answer
 
Its really simple just add event which you can directly select for designer or in code just write following in constructor

textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);



C#
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar))
        {
            e.Handled = true;
    }
        else
        {
            e.Handled = false;
    }
}
 
Share this answer
 
v2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900