CFLib.org – Common Function Library Project

IsZip(str)

Last updated May 08, 2002

author

Jeff Guillaume

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Tests passed value to see if it is a properly formatted U.S. zip code. Does not check actual validity/existence of zip code!

Return Values:
Returns a boolean.

Example:

<cfoutput>
#YesNoFormat(IsZipUS("48084"))#<br>
#YesNoFormat(IsZipUS("90210"))#<br>
#YesNoFormat(IsZipUS("02412-0356"))#<br>
#YesNoFormat(IsZipUS("ABC1234"))#<br>
</cfoutput>

Parameters:

Name Description Required
str String to be checked. Yes

Full UDF Source:

/**
 * Tests passed value to see if it is a properly formatted U.S. zip code.
 * 
 * @param str      String to be checked. (Required)
 * @return Returns a boolean. 
 * @author Jeff Guillaume (jeff@kazoomis.com) 
 * @version 1, May 8, 2002 
 */
function IsZipUS(str) {
    return REFind('^[[:digit:]]{5}(( |-)?[[:digit:]]{4})?$', str); 
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson