Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postcodes #82

Open
govuk-design-system opened this issue Jan 15, 2018 · 4 comments
Open

Postcodes #82

govuk-design-system opened this issue Jan 15, 2018 · 4 comments

Comments

@govuk-design-system
Copy link
Collaborator

@govuk-design-system govuk-design-system commented Jan 15, 2018

What

How to ask for a postcode.

Why

This pattern is often used separately to full addresses, for example to find things near a certain location

Services that use this pattern:

Anything else

@fofr
Copy link

@fofr fofr commented Mar 5, 2019

When asking for a postcode, how should it be validated?

There are some interesting options:

  • validate against a list of known postcodes (lists will never be complete and always up to date)
  • maximum length (allowing spaces)
  • alphanumeric only
  • postcode regular expressions (of varying types)
  • do users commonly enter hyphens instead of spaces?

Examples of special cases in the UK:
https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Special_cases

Discussion on postcode regular expressions:
https://stackoverflow.com/questions/164979/uk-postcode-regex-comprehensive
https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/488478/Bulk_Data_Transfer_-_additional_validation_valid_from_12_November_2015.pdf

Royal Mail's guidance – ie validating as Postcode Address File (PAF) valid:
https://www.royalmail.com/business/services/marketing/data-optimisation/paf

@fofr
Copy link

@fofr fofr commented Mar 5, 2019

This is the approach we're taking to validating and storing postcodes on DfE’s publish teacher training courses service: https://bat-design-history.herokuapp.com/publish-teacher-training/postcodes

@terrysimpson99
Copy link

@terrysimpson99 terrysimpson99 commented Mar 5, 2019

I raised this in a slack discussion and I think it's worth repeating here for github readers. I think we should accept input with non-postcode characters. For example the user might type an extra character by accident or cut&paste something with an extra character (such as 'BN12 4AX.') or they might include a hyphen instead of a space (it does happen). If a human received a postcode with spurious characters they'd just ignore the spurious characters. It's relatively simple in code terms and it's how the post office and court finder appear to do it, see: https://www.royalmail.com/find-a-postcode
https://courttribunalfinder.service.gov.uk/search/postcode

@StephenGill
Copy link

@StephenGill StephenGill commented Nov 18, 2019

For reference, here's the regex used to validate postcodes in register to vote: https://github.com/alphagov/ier-frontend/blob/master/app/uk/gov/gds/ier/validation/PostcodeValidator.scala

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants