Solved

Reg Expression Help ColdFusion

Posted on 2009-04-08
8
375 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

Don't Miss ATEN at InfoComm 2017!

Visit booth #2167 to see the  new ATEN VM3200 32 x 32 Modular Matrix Switch. Other highlights include the VE8950 4K HDMI Over IP Extender, VS1912 12-Port DP Video Wall Media Player  and VK2100 ATEN Control System. Register now with Free Pass Code ATEN288!

Question has a verified solution.

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

Suggested Solutions

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
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…

752 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