I am working on phone number box. I have already made the format of (888)888-8888
. But now I want to operate back space. If someone has given the wrong number so he can edit it.
The problem is that when I try to remove the last digits from right side. it stops removing the digits after 4 digits from end. It shows me the result like this (888)888-
.
Here is my code for number and dashes format.
if (phonebox.Text.ToString().Length == 1)
{
phonebox.Text = "(" + phonebox.Text.ToString();
phonebox.Select(phonebox.Text.Length, 0);
}
else if (phonebox.Text.ToString().Length == 4)
{
phonebox.Text = phonebox.Text.ToString() + ")";
phonebox.Select(phonebox.Text.Length, 0);
}
else if (phonebox.Text.ToString().Length == 8)
{
phonebox.Text = phonebox.Text.ToString() + "-";
phonebox.Select(phonebox.Text.Length, 0);
}
here is the solution that I attempted but not sure whether it will work.
else if (phonebox.Text.ToString().Length == 9)
{
phonebox.Text = phonebox.Text.ToString()+"";
phonebox.Select(phonebox.Text.Length, 0);
}