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

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

Postcodes #82

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


Copy link

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


How to ask for a postcode.


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

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:

Discussion on postcode regular expressions:

Royal Mail's guidance – ie validating as Postcode Address File (PAF) valid:

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:

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:

Copy link

@StephenGill StephenGill commented Nov 18, 2019

For reference, here's the regex used to validate postcodes in register to vote:

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

Successfully merging a pull request may close this issue.

None yet
5 participants