Solved

Reg Expression Help ColdFusion

Posted on 2009-04-08
8
378 Views
Last Modified: 2013-12-24
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})$
 
^(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

0
Comment
Question by:asaworker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 19

Accepted Solution

by:
erikTsomik earned 167 total points
ID: 24097472
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))$

CAnadian
[A-Z]\d[A-Z]\s\d[A-Z]\d


ALso try using this site with already built in functionality
http://www.cflib.org/udf/IsZip



0
 

Author Comment

by:asaworker
ID: 24097631
Thanks for the link, but I need what I sent combined.
0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24097709
OK.What happens if the person is austalian but entered the US post code it will still let you through
0
Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

 

Author Comment

by:asaworker
ID: 24097764
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.
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 167 total points
ID: 24098151
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

http://www.cflib.org/index.cfm?event=page.udfbyid&udfid=218
http://www.cflib.org/udf/IsZIPUK
http://www.cflib.org/udf/IsZip
0
 
LVL 16

Expert Comment

by:duncancumming
ID: 24110112
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.

e.g.



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

Open in new window

0
 
LVL 16

Assisted Solution

by:duncancumming
duncancumming earned 166 total points
ID: 24110225
PS: erik, have you seen this file that defines the postcode schema:
http://www.govtalk.gov.uk/gdsc/schemaHtml/bs7666-v2-0-xsd-PostCodeType.htm

0
 

Author Comment

by:asaworker
ID: 24571886
Can we use that for our coldfusion pattern
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
What You Need to Know when Searching for a Webhost Provider
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question