Help Validate Phone Number Using IdexOf, IsNumeric and Substrings

Posted on 2006-05-02
Last Modified: 2008-01-09
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

Question by:Albeej221
    LVL 23

    Expert Comment

    by:Jens Fiederer
    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.

    Author Comment

    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....
    LVL 85

    Accepted Solution

    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....

    Author Comment

    Thank you Idle,

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now