home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / windows / ocx / valid.exe / VALID.BAS < prev    next >
Encoding:
BASIC Source File  |  1996-05-24  |  2.8 KB  |  87 lines

  1. Attribute VB_Name = "modValid"
  2. Option Explicit
  3.  
  4. ' This function checks the phone number passed in.
  5. ' The phone number must be in the format XXX-XXX-XXXX
  6. Function CheckPhoneNumber(PhoneNumber)
  7.     Dim Index ' used to scan phone number
  8.     
  9.     ' If the phone number is the wrong length,
  10.     ' it's bad ... don't bother to scan
  11.     If Len(PhoneNumber) <> 12 Then
  12.         CheckPhoneNumber = False
  13.         Exit Function
  14.     Else
  15.         For Index = 1 To 12
  16.             Select Case Index
  17.                 Case 4, 8 ' Check for hypens
  18.                     If Mid(PhoneNumber, Index, 1) <> "-" Then
  19.                         CheckPhoneNumber = False
  20.                         Exit Function
  21.                         End If
  22.                         
  23.                 Case Else ' Check for digits
  24.                     If Not IsDigit(Mid(PhoneNumber, Index, 1)) Then
  25.                         CheckPhoneNumber = False
  26.                         Exit Function
  27.                         End If
  28.                 End Select
  29.             Next Index
  30.         End If
  31.         
  32.     ' We made it through the whole phone number,
  33.     ' must be good.
  34.     CheckPhoneNumber = True
  35.     End Function
  36.  
  37. Function CheckZipCode(ZipCode)
  38.     Dim Index
  39.     
  40.     Select Case Len(ZipCode)
  41.         Case 5, 9 ' normal five digit Zip Code or
  42.                   ' nine digit Zip Code w/o hyphen
  43.                   
  44.             ' Check each characer in the Zip Code
  45.             ' Each one must be a digit.
  46.             For Index = 1 To Len(ZipCode)
  47.                 If Not IsDigit(Mid(ZipCode, Index, 1)) Then
  48.                     CheckZipCode = False
  49.                     Exit Function
  50.                     End If
  51.                 Next Index
  52.                 
  53.         Case 10 ' nine digit zip code w/ hyphen
  54.             ' Check each characer in the Zip Code
  55.             ' The sixth character must be a hyphen,
  56.             ' the rest must be digits.
  57.             For Index = 1 To Len(ZipCode)
  58.                 ' Check for the hyphen
  59.                 If (Index = 6) And (Mid(ZipCode, Index, 1) <> "-") Then
  60.                     CheckZipCode = False
  61.                     Exit Function
  62.                 ' Check for the digits.
  63.                 ElseIf (Index <> 6) And (Not IsDigit(Mid(ZipCode, Index, 1))) Then
  64.                     CheckZipCode = False
  65.                     Exit Function
  66.                     End If
  67.                 Next Index
  68.         
  69.         Case Else ' error
  70.             CheckZipCode = False
  71.             Exit Function
  72.         End Select
  73.         
  74.     ' We made it through every check.  This Zip
  75.     ' Code must be good.
  76.     CheckZipCode = True
  77.     End Function
  78.  
  79.  
  80. ' This function returns True if the character passed in is
  81. ' a decimal digit.  False, otherwise.
  82. Function IsDigit(Character)
  83.     IsDigit = (InStr("0123456789", Character) <> 0)
  84.     End Function
  85.  
  86.  
  87.