Hi,
you can use the regular expression or you can catch the key press event and stopping form use typing unwanted keys.
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if ((!char.IsNumber(e.KeyChar)) && (!char.IsSymbol(e.KeyChar )))
{
e.Handled = false;
}
}
If the user press on any key that is not a number or a symbol, then the handle will be rejected, so the text box will not accept that key.
If you are specifically looking for that "+" symbol, then the code will be
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if ((char.IsNumber(e.KeyChar)) || (e.KeyChar == '+'))
{
e.Handled = true;
}
else
{
e.Handled = false;
}
}
I hope this helps.
Regards
Jegan