1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Strings and Substrings

Discussion in 'Visual Basic ( VB )' started by John B, Aug 26, 2007.

  1. John B

    John B Banned

    Joined:
    Aug 24, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I'm trying to create a program that will validate phone numbers. I need to use strings and substring to tell if it is using the hyphens in the phone numbers. If it is not a validate phone number a message will show saying that it is not validate and why. If it is validate then it will show a message that is it.
     
  2. jwshepherd

    jwshepherd New Member

    Joined:
    Aug 13, 2007
    Messages:
    135
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    VP Technology Corporation
    Location:
    Texas
    Home Page:
    use a form with one textbox, one label,one command button
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim strTemp As Integer, strLen As String, x As Integer, strPhone As String
    strPhone = Text1.Text
    strLen = Len(strPhone)
    For x = 1 To strLen
        strTemp = Asc(Mid$(strPhone, x, 1))
        If strTemp = 45 Then strTemp = 0
        If strTemp < 48 Or strTemp > 57 Then
        Label1.Caption = "You must only use numbers"
        Else
        Label1.Caption = "Thank you "
        End If
        
        Next
    
    End Sub
    
     
    Last edited: Aug 27, 2007
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    I think other than hyphen (-) there are some other characters which are valid in phone numbers and they are plus (+) and brakets ( () ). +91-(348)-321654987 should be a valid phone number.
     
  4. jwshepherd

    jwshepherd New Member

    Joined:
    Aug 13, 2007
    Messages:
    135
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    VP Technology Corporation
    Location:
    Texas
    Home Page:
    if you need thosejust add the follwing lines
    Code:
       
        If strTemp = 45 Then strTemp = 0    'for -
        If strTemp = 43 Then strTemp = 0    'for +
        If strTemp = 40 Then strTemp = 0    'for (
        If strTemp = 41 Then strTemp = 0    'for )
    
     

Share This Page