Address formats
Posted on 18 Jun 2009 at 11:48
Simon Jones tackles the tricky subject of handling addresses in applications, both within the UK and far beyond.
If you don't have access to the full PAF, there are other ways to validate a postcode. This regular expression can be used to check that a postcode has the right letters and numbers, in the right order, so that at least it is a permissible postcode:
(GIR 0AA|[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})
Comparing a possible postcode against this regular expression will weed out obvious problems such as not having the right number of characters, or using letters that aren't allowed at a particular position - for instance, the letters C, I, K, M, O and V aren't allowed as either of the final two characters. Notice how the regular expression starts with one of the exceptions, by allowing "GIR 0AA", the postcode for the old Post Office Girobank that's still used today by the Alliance & Leicester Commercial Bank, which took over the business in 1989. Checking a postcode against a regular expression is easy in VB.NET or any other .NET language, since there's a RegEx class built in that provides an IsMatch function. You just have to pass it the string you want to test and the regular expression string you want to match against:
If System.Text.RegularExpressions.Regex.IsMatch(strFullPostcode, strRegExPostcodeValidator) Then
...
End If
If you want to go further, lists of all the valid region codes - the one or two letters at the start of each postcode - are available on the internet; a few sites encourage individuals to plot their own postcodes on a map, which makes the resulting data available for free. One of the best is New Popular Edition Maps (www.npemap.org.uk), which uses old Ordnance Survey maps from the 1930s and 1940s that are now out of copyright - these have been scanned and stitched together to give a patchwork map of England, Wales and Scotland, although maps of Northern Ireland don't come out of copyright for a few years yet. There are about 1.7 million unique postcodes in the UK (covering the 27 million addresses at an average of 15 addresses per postcode) and NPE Maps has so far collected 41,718 of these. Even though this represents only 2.5% of all the postcodes in the UK, the site has 98% of the outward codes (the first half of a postcode) and 93% of the sectors (the outward half plus the first digit of the inward half). The biggest problems facing the site's database are cleaning mistakes - where people entered the wrong postcode or clicked the wrong place on the map - and getting that last few per cent of the data.
If you want the official list of postcode sectors you can buy the Post Town Gazetteer from the Royal Mail for just £50, which lists the outward code and inward sector for all postcodes, plus the corresponding post town and the old county. Using this information, you can reduce the data-entry burden for a new address to just typing the postcode and house number. You can buy similar data for many countries of the world from www.geopostcodes.com, which includes latitude and longitude data.
CEDEX headache
The biggest problem I've had when dealing with European addresses is the French CEDEX system. Courrier d'Entreprise ? Distribution EXceptionnelle (CEDEX) is designed for recipients of large volumes of mail, in which each organisation is allocated its own unique postal code; you have to use that code followed by the word CEDEX to have the letter delivered. La Post, the French postal service, would like you to write the postal code, city, the word CEDEX and possibly a sector or Arrondissement number all on one line, in that order, so for example:
Simon Jones
Simon is a contributing editor to PC Pro. He's an independent IT consultant specialising in Microsoft Office, Visual Basic and SQL Server.
advertisement
- Getting to grips with Microsoft's IT Health Environment Scanner
- Virtualise your servers
- The changing face of travel gadgets
- Build your own distributed file system
- The bulletproof Dell that costs an arm and a leg
- Microsoft Office 2010 Technical Preview: Q&A
- Lawnmowers, the TyTN II and one odd insurance request
- There'll never be a bulletproof OS
- How far can we trust apps?
- Five nice touches in Outlook 2010
- Why Britain's watchdogs have fewer teeth than goldfish
- Tabbed documents: how to make Office 2010 great
- Outlook 2010 People Pane – does it spell death to Xobni
- Microsoft Outlook 2010 screenshots
- Co-Authoring in Word 2010 and SharePoint Foundation 2010
- Microsoft Outlook 2010 screenshots: Backstage view
- Flash 10.1: Developing for Desktop and Device
- Microsoft Office 2010 screenshots: Recover unsaved items
- Microsoft Word 2010 screenshots: Text Effects
- Microsoft Word 2010: inserting screenshots
- Q&A: Why Conficker was a victim of its own success
- App developers losing faith in Android
- Biz Stone: Murdoch's Google veto will "fail fast"
- Google adds automatic captions to YouTube
- China ramps up cyber spying
- Mozilla maintains dependence on Google
- Windows 7 flying off the shelves
- Google Chrome OS: full details unveiled
- AOL slashes 2,500 jobs
- YouTube begins streaming full-length shows
advertisement
Printed from www.pcpro.co.uk


