IsZip Function:

The IsZip function tests a string or a long for validity as a zip code. IsZip will validate either five (xxxxx) or nine digit (xxxxx-xxxx) zip codes. While the IsZip will not verify a zip code, it will ensure that the input is in valid zip code format. Returns True if the input is recognized as a zip code or False if the input is not a zip code. Null or Empty input returns False.

Syntax:
boolean = IsZip(zipcode)
Example Usage:
<%
 ' IsZip returns true
response.write IsZip(14450) & "<BR>"
response.write IsZip(10036) & "<BR>"
response.write IsZip("31200-6514") & "<BR>"

 ' IsZip returns False
response.write IsZip(6500) & "<BR>"
response.write IsZip(112012) & "<BR>"
response.write IsZip("3154-88542") & "<BR>"
response.write IsZip("1152A-0SDX") & "<BR>"
%>
ASP Source Code:
<%
Private Function IsZip(byVal zipcode)
	Dim reg
	if IsNull(zipcode) then
		IsZip = False
		exit function
	elseif IsEmpty(zipcode) then
		IsZip = False
		exit function
	end if
	zipcode = Trim( CStr( zipcode ) )
	Select Case Clng( Len(zipcode) )
		Case 10
			Set reg = New RegExp
			With reg
				.IgnoreCase = True
				.Global = True
				.Pattern = "[0-9][0-9][0-9][0-9][0-9]" & _
					   "-[0-9][0-9][0-9][0-9]"
				If .Test(zipcode) Then
					IsZip = True
				Else
					IsZip = False
				End If
			End With
			Set reg = Nothing
			Exit Function
		Case 5
			Set reg = New RegExp
			With reg
				.IgnoreCase = True
				.Global = True
				.Pattern = "[0-9][0-9][0-9][0-9][0-9]"
				If .Test(zipcode) Then
					IsZip = True
				Else
					IsZip = False
				End If
			End With
			Set reg = Nothing
			Exit Function
		Case Else
			IsZip = False
			Exit Function
	End Select
End Function
%>