textBox1_KeyPress (Question)

  • Thread starter Thread starter Claudia Fong
  • Start date Start date
C

Claudia Fong

Hi,

I would like to control the user's input; In a textBox where the user is
only allow to put 0-9 (eg telephone number) I want to show a messagebox
if a user inputs a character like a-z..

Can someone help me with this?

Here's the code I started with, but don't know how to finish..

private void textBox1_KeyPress(object
sender,System.Windows.Forms.KeyPressEventArgs e)
{
string ex;
if(e.KeyChar ---> this will get the input's char.
MessageBox.Show("ERROR");
}



Cheers!

Claudi
 
Hi,

if(!Char.IsDigit(e.KeyChar))
{
MessageBox.Show("ERROR");
e.Handled = true;
}
 
Back
Top