VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Validates ZIP code

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)

Validates ZIP code

Rate Validates ZIP code



' 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


Download this snippet    Add to My Saved Code

Validates ZIP code Comments

No comments have been posted about Validates ZIP code. Why not be the first to post a comment about Validates ZIP code.

Post your comment

Subject:
Message:
0/1000 characters