Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reg Expression Help ColdFusion

Posted on 2009-04-08
8
Medium Priority
?
387 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 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
Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

 

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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
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…

722 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