I look for the way to validate data entered into a textbox which is used to get the value entered and take it to mathematical formulas. Now create a function which the user can only enter numbers (0-9), and the characters ".", "," And "-" to write decimals and negatives, but my problem is: when the user enters something like: "..-", ",.,", "-." the program gives error. Could you help me? Thanks in advance. I leave the function to validate as I have until this minute
public static void SoloNumeros(KeyPressEventArgs V)
{
if (Char.IsDigit(V.KeyChar))
{
V.Handled = false;
}
else if (Char.IsControl(V.KeyChar))
{
V.Handled = false;
}
else if (Char.IsControl(V.KeyChar))
{
V.Handled = false;
}
else if (V.KeyChar.ToString().Equals("."))
{
V.Handled = false;
}
else if (V.KeyChar.ToString().Equals(","))
{
V.Handled = false;
}
else if (V.KeyChar.ToString().Equals("-"))
{
V.Handled = false;
}
else
{
V.Handled = true;
MessageBox.Show("Por favor, introduzca solo nùmeros.");
}
}