-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,173
  • 68
  • 59
  • 86

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
  • 195,137
  • 36
  • 275
  • 343
-1

try this,

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

in your KeyPress or KeyUp event.