Results 1 to 6 of 6

Thread: Phone Number

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    72

    Wink Format Phone Number

    I am trying to check and make sure that the User has entered a proper format Phone number

    555-555-5555
    or
    555-5555

    i tried to use the

    Code:
    textbox.text<>format(textbox.text,"###-####)
    and
    Code:
    textbox.text<>format(textbox.text,"###-###-####)
    but if i enter 1234-55
    it says that it is valid. How can i make sure that all the pos-holders are filled

    thanks
    VB 6 Professional Edition

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    you would do better to use the MaskeditControl
    with it you specify a mask ###-###-####
    and that is what you get

    or your just allow the user to enter 9 digits and format it in your code.
    If len(text1.text) = 9 then
    myVariable = format(text1.text,"###-###-####")
    else
    msgbox "Sorry, you need 9 digits
    Endif

    as an additive, I personally would store my phone numbers as 9 digit numbers without the - I use a masked edit box but I don't store 905-555-6666 I store 9055556666

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Guest
    here is some code I wrote to check for validation for a 7 digit phone number if you need nine, just change the position of the "-" and add more cases


    Code:
    Private Sub Command1_Click()
    Dim Bln(7) As Boolean
    Dim TheLetter As String
    Dim TheWhole As Boolean
    
      TheWhole = True
    
      For i = 1 To Len(Text1)
        TheLetter = Mid$(Text1, i, 1)
        Select Case i
            
          Case 1
            If IsNumeric(Val(TheLetter)) Then
              Bln(i - 1) = True
            End If
          Case 2
            If IsNumeric(Val(TheLetter)) Then
              Bln(i - 1) = True
            End If
          Case 3
            If IsNumeric(Val(TheLetter)) Then
              Bln(i - 1) = True
            End If
          Case 4
            If TheLetter = "-" Then
              Bln(i - 1) = True
            End If
          Case 5
            If IsNumeric(Val(TheLetter)) Then
              Bln(i - 1) = True
            End If
          
          Case 6
            If IsNumeric(Val(TheLetter)) Then
              Bln(i - 1) = True
            End If
      
          Case 7
            If IsNumeric(Val(TheLetter)) Then
              Bln(i - 1) = True
            End If
      
          Case 8
            If IsNumeric(Val(TheLetter)) Then
              Bln(i - 1) = True
            End If
    
        End Select
      Next
    
      For i = 0 To 7
        If Bln(i) = False Then
          TheWhole = False
        End If
      Next
    
      If TheWhole = False Then
        MsgBox "wrong format"
      End If
    
    End Sub

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Or even better, case 1 to 8!

  5. #5
    Guest
    we need to skip 4, so 1 to 8 wouldnt work.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
    IF textbox.text Like "###-###-####" or textbox.text like "###-####" then Msgbox "proper number"
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width