i'm using regex to keep input into a text box numbers only and trying to make any non number inserted removed
private void txtNex_TextChanged(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(txtNex.Text, "[^0-9]"))
{
MessageBox.Show("insert numbers only");
if (txtNex.Text.Length > 1)
{
txtNex.Text = txtNex.Text.Substring(0, txtNex.Text.Length - 1);
}
else
{
txtNexFixPhone.Text = "0";
}
}
}
the problem is while it does work there is some sort of a bug (or my own lack of knowledge) that moves the input to the beginning and if i enter another non numerical it will make a loop that removes all text
so lets say i enter
123a
it will give me and error messagebox and remove the "a" now if i try to input another "a" it will come before the 123
a123
ending with an error loop that will delete all input