Problem
A Textbox should only allow numbers and decimals
Approach
Using the Keypress method will validate on each key that is entered.
Call the code below onKeyPress Event of each Textbox with
validateNumber(sender, e);
after each
Solution
private void validateNumber(object sender, KeyPressEventArgs e) { if ((e.KeyChar == ',') && (((TextBox)sender).Text.IndexOf(',') > -1)) { e.Handled = true; return; } if (!Char.IsDigit(e.KeyChar)) { if ((e.KeyChar != ',') && (e.KeyChar != Convert.ToChar(Keys.Back))) { e.Handled = true; return; } } }