Validate TextBox for Phone Numbers

  • I was trying to validate a phone number before proceeding and was using TextBox.SetFocus to return to the textbox in question when there was an error, but it proceeded to the next control anyway. I gave up on that and modified some code I found from Dave (which cured the SetFocus problem).

    The code below gives me the msgbox no matter what. I changed the code to allow for just the 10 digit phone number, and for the () and spaces. What am I doing wrong? Is there a better way?

    All I'm trying to do is verify that the user has plugged in a 10-digit phone number. If not, set focus back to the offending textbox, otherwise, format the textbox and move on.

  • Re: Textbox.SetFocus

    OK, I see. The error is: the length will ALWAYS be NOT 10 OR 14.

    What's the most efficient way to vaildate a phone number?

  • Re: Textbox.SetFocus

    I ended up going with this. It works pretty well, but I am always interested in how others would have approached it. Especially when it is more efficient.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!