Solved

Reg Expression Help ColdFusion

Posted on 2009-04-08
8
363 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 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
 

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now