Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Reg Expression Help ColdFusion

Posted on 2009-04-08
8
Medium Priority
?
394 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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 19

Accepted Solution

by:
erikTsomik earned 668 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
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.

 

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 668 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 664 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
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…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

916 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