Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Validation: support address, check postcode regex isnt too clever #71

Closed
NickColley opened this issue Mar 22, 2020 · 6 comments · Fixed by #114
Closed

Validation: support address, check postcode regex isnt too clever #71

NickColley opened this issue Mar 22, 2020 · 6 comments · Fixed by #114
Labels
question Further information is requested

Comments

@NickColley
Copy link
Contributor

It looks a bit clever, we need to make sure it doesnt restrict input by making too many assumptions about postcodes.

@NickColley NickColley added the question Further information is requested label Mar 22, 2020
@huwd
Copy link
Member

huwd commented Mar 22, 2020

Humm this might be tough,
I remember reading this once:
https://github.com/mysociety/mapit/blob/f186a5dd13f71e63486d0ac792cd3bca8f72ebfc/mapit_gb/countries.py

@brucebolt
Copy link
Member

When this was first implemented (for the Brexit EU Funding Form), we took the regex from https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation.

This seems to cover all formats of UK postcode, plus the BFPO addresses, non-geographic special cases and British Overseas Territories.

@huwd
Copy link
Member

huwd commented Mar 22, 2020

SPECIAL_POSTCODES = (
    'ASCN1ZZ',  # Ascension Island
    'BBND1ZZ',  # BIOT
    'BIQQ1ZZ',  # British Antarctic Territory
    'FIQQ1ZZ',  # Falkland Islands
    'PCRN1ZZ',  # Pitcairn Islands
    'SIQQ1ZZ',  # South Georgia and the South Sandwich Islands
    'STHL1ZZ',  # St Helena
    'TDCU1ZZ',  # Tristan da Cunha
    'TKCA1ZZ',  # Turks and Caicos Islands
    'GIR0AA', 'G1R0AA',  # Girobank
    'SANTA1', 'XM45HQ',  # Santa Claus
)

@huwd
Copy link
Member

huwd commented Mar 22, 2020

!? the santa claus postcode is real

@NickColley
Copy link
Contributor Author

as long as you're confident and have used the logic elsewhere, feel free to close :)

@brucebolt
Copy link
Member

We could probably simplify the regular expression by removing the British Overseas Territories. If we don't already have it, we should probably have a test to check the following are all valid:

AA9A 9AA
A9A 9AA
A9 9AA
A99 9AA
AA9 9AA
AA99 9AA
BFPO 1
BFPO 9

Plus all of the above without a space.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants