Help Validate Phone Number Using IdexOf, IsNumeric and Substrings

I need some help getting pointed in the right direction. I have to create a program that validates phone numbers, but I have to use the following criteria in it.  I need to use substrings to break the number down into 3 groups "999", "999", "9999".  I have to use the IndexOf and IsNumeric Functions of  I cannot use any other functions except those listed.

_**The application should accept a maximum of 12 characters. When the user clicks a button, the program should determine if the entry is of the form 999-999-9999, where the character 9 represents any number. "
"Check that the user has entered two dashes in the appropriate spaces.

-**Break the string into 3 substrings, represented as 999,999, and 9999.
-**Check that the user has entered two dashes in the appropriate spaces.
-**Check to see if each part is only numeric characters, using IsNumeric and IndexOf.
    If error, display error message box.
-**You don’t have to use loops (you can if you want to), but you have to use the if-then-else statement

Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Here is an example of how to use the IndexOf() method:

        Dim s As String = "a.b.c"
        Dim firstPeriod As Integer = s.IndexOf(".")
        Dim secondperiod As Integer = s.IndexOf(".", firstPeriod + 1)

        Debug.WriteLine("firstPeriod = " & firstPeriod)
        Debug.WriteLine("secondPeriod = " & secondperiod)

        If firstPeriod <> -1 And secondperiod <> -1 Then
            MsgBox("string HAS at least two periods")
            MsgBox("string does NOT have two periods")
        End If

See if you can apply that to your problem and then post back with your code....
Jens FiedererTest Developer/ValidatorCommented:
This looks like a homework assignment...real-life problems don't have such restrictions.

We can help you out if you are having a specific problem - where is the difficulty?  Do you not understand how to use substrings?

But we can't do your homework for you.
Albeej221Author Commented:
It is indeed, I didn't expect it to be done for me. :)

I am just having a hard time getting started. I don't understand how to incorporate the indexOf and how to assign the substrings....
Albeej221Author Commented:
Thank you Idle,

seeing it in that context does help me to see the IndexOf's function/purpose.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.