[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

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

  • 2
1 Solution
Jens FiedererCommented:
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....
Mike TomlinsonMiddle 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....
Albeej221Author Commented:
Thank you Idle,

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


Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now