Reg Expression Help ColdFusion

I am trying to combine the following regular expressions to validate UK, Canadaina, US and Australian postal codes
^(\d{5}((|-)-\d{4})?)|([A-Za-z]\d[A-Za-z][\s\.\-]?(|-)\d[A-Za-z]\d)|[A-Za-z]{1,2}\d{1,2}[A-Za-z]? \d[A-Za-z]|{2}|(0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2})$

Open in new window

Who is Participating?
erikTsomikConnect With a Mentor System Architect, CF programmer Commented:
here is the regular expression to validate UK postal code
^([A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\ [0-9][ABD-HJLNP-UW-Z]{2}|(GIR\ 0AA)|(SAN\ TA1)|(BFPO\ (C\/O\ )?[0-9]{1,4})|((ASCN|BBND|[BFS]IQQ|PCRN|STHL|TDCU|TKCA)\ 1ZZ))$


ALso try using this site with already built in functionality

asaworkerAuthor Commented:
Thanks for the link, but I need what I sent combined.
erikTsomikSystem Architect, CF programmer Commented:
OK.What happens if the person is austalian but entered the US post code it will still let you through
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

asaworkerAuthor Commented:
sure, but we have clients in australia that enter in australian zip codes, I need to account for british, canadian, australian and us zip codes mostly.
_agx_Connect With a Mentor Commented:
I think your code would be much easier to read and maintain if you used separate checks for each zip code type. I do not know about Australian zip codes, but cflib has functions for Canada, UK and US zip codes
yeah, what you need is to call separate functions for each type you need.  then have one master function to validate all.  As _agx_ says.


<cffunction name="checkZip" returntype="boolean" output="no">
	<cfargument name="zip" required="yes" type="string">
	<cfif 	IsZipUK( OR 
			IsZipAU( OR 
			IsZipUS( OR 
		<cfreturn true>
	<!--- invalid format --->
		<cfreturn false>

Open in new window

duncancummingConnect With a Mentor Commented:
PS: erik, have you seen this file that defines the postcode schema:

asaworkerAuthor Commented:
Can we use that for our coldfusion pattern
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.