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
}
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
}
private void your_textBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar))
{
// is a number
}
else
{
// is anything else
}
}
try this,
textBox1.Text = string.Concat(textBox1.Text.Where(char.IsLetterOrDigit));
in your KeyPress or KeyUp event.