-1

On KeyPress or KeyUp event, how can I do something like this:

if (String.IsOnlyANumber(textBox.Text))
{ 
    do my things
}
else if(String.IsLettersAndEverythingElse(textBox.Text))
{
    do my other things
}
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92

2 Answers2

0
private void your_textBox_KeyPress(object sender, KeyPressEventArgs e)
{
    if (char.IsDigit(e.KeyChar)) 
    {
        // is a number
    }
    else 
    {
        // is anything else
    }
}
juergen d
  • 201,996
  • 37
  • 293
  • 362
-1

try this,

textBox1.Text = string.Concat(textBox1.Text.Where(char.IsLetterOrDigit));

in your KeyPress or KeyUp event.