I am trying to validate phone number textbox. I just want user to be able to enter only numeric values and only 10 digits in the textbox. I did it using keypress event.
it works fine but the problem is once the length of the input reaches to 10, it wont even allow the backspace.
Here is my code -
Private Sub tbphone_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbphone.KeyPress
If Not (Char.IsDigit(CChar(CStr(e.KeyChar))) Or e.KeyChar = ChrW(Keys.Back)) Or tbphone.Text.Length >= 10 Then e.Handled = True
End Sub
Now, there can be a scenario where user enters all digits correctly but the last one. In that case he will not be able delete that last digit perhaps he will not be able to do anything in that textbox as the length of the input text is already 10 and now the e.handled is set to true.
Please suggest how can I achieve it...