2

I'm formatting addresses imported from the Sample Royal Mail PAF to Royal Mail Specification.

In the programmer's guide there are two examples with similar fields:

Table 8: Building Number in the Building Name field

Field on PAF                  Fictional example
Sub Building Name             FLAT 1
Building Name                 HOLLY HOUSE
Thoroughfare                  OAK AVENUE
Locality                      BIDDENDEN
Post Town                     ASHFORD
Postcode                      TN27 8B

Table 10: Address with Sub Building Name, & using a range in Building Name field

Field on PAF                  Fictional example
Sub Building Name             CARETAKERS FLAT
Building Name                 110-114
Thoroughfare                  HIGH STREET WEST
Post Town                     BRISTOL
Postcode                      BS1 2AW 

These should be formatted as below:

Flat 1, Holly House
Oak Avenue
Biddenden
ASHFORD
TN27 8BT 

Caretakers Flat
110-114 High Street West
BRISTOL
BS1 2AW 

What is the correct logic to determine whether the Sub Building Name should appear on the first line with the Building Name or Building Name should be on the second line with the Thoroughfare?

Note that I have tested checking for a digit in Building Name but it fails where Building Name has the value 10 Sellon Court and produces 10 Sellon Court Western Approach

Asa Carter
  • 2,207
  • 5
  • 32
  • 62

1 Answers1

1

I found the answer further in the documentation:

Exception Rule indicators:

i) First and last characters of the Building Name are numeric (eg ‘1to1’ or ’100:1’)

ii) First and penultimate characters are numeric, last character is alphabetic (eg 12A’)

iii) Building Name has only one character (eg ‘A’)

Asa Carter
  • 2,207
  • 5
  • 32
  • 62
  • 1
    This probably comes a bit late, but there's a Node.js library which can parse raw Royal Mail records into formatted address lines which takes into account issues like the building exception rule. https://github.com/cblanc/uk-clear-addressing. The test suite covers all the examples in the PAF developer docs. Full Disclosure: I wrote it. – C Blanchard Dec 04 '14 at 10:47
  • Thanks Chris that looks really helpful. From my tests in the sample PAF, I found that in certain circumstances there could also be a line 4 before the post town. Did you find that in any of your tests? – Asa Carter Dec 04 '14 at 15:22
  • Yes, found it a while back but never made it into the library. So I updated just now. It can happen with organisations with long addresses - the lib will merge the extra lines into line 3 separated with commas. I found one other edge case not listed in the docs - an address with just a sub building name. I think that one was a typo in PAF. That case has also been added as well as some performance improvements for bulk formatting. – C Blanchard Dec 05 '14 at 07:55