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:
From around the web
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
- How to make Google AdWords work for your business
- The curse of sloppily written software
- Paying for your crimes with Bitcoin
- Behind the scenes: tech support for Formula 1
- The security risk of fat fingers
- Why Windows Phone 7 isn't quite ready for business
- When will Microsoft stop fiddling with Windows 8?
- Flash down the pan?
- Metro Style apps vs desktop applications
- Coping with Facebook changes
- Chrome's shine getting lost in translation
- BytePac: the cardboard hard disk enclosure
- How tech loosens our grip on reality
- Hokum watch: Safer Internet Day
- Why I'm deleting Adobe from my PC
- Prepare to be patronised: it's Safer Internet Day
- Dear Sony, Samsung and every other tech company in the world: stop trying to be Apple
- Will Apple's Final Cut Pro X update placate the pros?
- Smartr Contacts for iPhone review
- Switching to Office 365's Outlook Web App
- VeriSign slammed for security breach cover-up
- SAP willing to share HANA with Oracle
- Why using a tablet could harm your health
- New RIM boss: no need for drastic change
- RIM founders fall on their swords
- Slow economy helps boost Red Hat revenue by 23%
- Google+ pages get multiple admins
- One in five companies lack card industry compliance
- Oil industry warns hacking attacks could kill
- British workers fear email monitoring
advertisement

