by Ian Lent (6 Submissions)
Category: String Manipulation
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Sun 16th January 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Validate 5 and 10-digit ZIP code format.
' Purpose: Checks to see if strZIP is in the format of a valid ZIP code.
' In: strZIP - Candidate ZIP code
' Out:
' Returns: True - if strZIP is in the format of a valid ZIP code
' False - if it is not
' Date: 1/16/2000
' Programmer: Speed Demon
' Last Modified:
' Notes: ZIP codes can be in the form 'xxxxx' or 'xxxxx-xxxx' where x is numeric.
' Assume it is a valid zip
ValidateZIP = True
Select Case Len(strZIP)
Case 5 ' xxxxx
If Not IsNumeric(strZIP) Then ValidateZIP = False
Case 10 ' xxxxx-xxxx
If Not IsNumeric(Left$(strZIP, 5)) _
Or Not IsNumeric(Right$(strZIP, 4)) _
Or Mid$(strZIP, 6, 1) <> "-" Then ValidateZIP = False
Case Else ' strZIP does not contain the right number of characters.
ValidateZIP = False
End Select
End Function