I have a textbox which needs only accept numbers (can be decimal values) and negative values.
Currently I have something like this in KeyPress event
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
{
e.Handled = true;
}
What else I should do in order to allow negative values?
Thanks
As L.B correctly mentioned in the comments this won’t allow some advanced notations like
3E-2, but for simple numbers it will do the trick.