CFLib.org – Common Function Library Project

IsZIPUK(str)

Last updated October 30, 2008

author

Duncan

Version: 2 | Requires: CF5 | Library: StrLib

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

Return Values:
Returns a Boolean.

Example:

<cfoutput>
OX4 1XP: #YesNoFormat(IsZipUK("OX4 1XP"))#<br>
OX11 0AL: #YesNoFormat(IsZipUK("OX11 0AL"))#<br>
O11 0AS: #YesNoFormat(IsZipUK("O11 0AS"))#<br>
RG1 AP: #YesNoFormat(IsZipUK("RG1 AP"))#<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.K. postcode (zip code).
 * v1 by Robert West
 * 
 * @param str      String to be checked. (Required)
 * @return Returns a Boolean. 
 * @author Duncan (duncan@duncancumming.co.uk) 
 * @version 2, October 30, 2008 
 */
function IsZipUK(str) {
return REFind("(GIR 0AA)|((([ABCDEFGHIJKLMNOPRSTUWYZ][0-9][0-9]?)|(([ABCDEFGHIJKLMNOPRSTUWYZ][ABCDEFGHKLMNOPQRSTUVWXY][0-9][0-9]?)|(([ABCDEFGHIJKLMNOPRSTUWYZ][0-9][ABCDEFGHJKSTUW])|([ABCDEFGHIJKLMNOPRSTUWYZ][ABCDEFGHKLMNOPQRSTUVWXY][0-9][ABEHMNPRVWXY])))) [0-9][ABDEFGHJLNPQRSTUWXYZ]{2})", 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