Key takeaways
- Put the recipient and premises first, with the postcode normally at the bottom
- Treat Post Town as a postal element rather than guessing it from a familiar city name
- Do not make County universally required
- Store a postcode as text and preserve its significant internal space
Authorship and review
Read our editorial and review principles- Written by
- Random Address Generator Editorial Team
- Reviewed by
- International Address Format Review Team
- Latest substantive update
- Rechecked UK address hierarchy, Post Town handling, and postcode test cases against Royal Mail lookup guidance and HTML address-field conventions.
The standard order of a UK address
A UK address normally moves from the recipient and premises to the postal locality: recipient, building or flat, street, optional dependent locality, Post Town, and postcode. Some homes have a building name without a street number. A validator that requires every address to begin with digits will reject legitimate shapes.
Unlike a US form, a UK form does not have one nationwide State field that must always be completed. Making County mandatory often forces people to invent a value or repeat information that the postal address does not need.
Mapping the address to online form fields
Do not mechanically turn every printed line into a fixed database column. Preserve the entered lines, then keep Post Town and postcode in searchable fields. Address Line 2 should be optional and able to hold a flat, building, or dependent-locality detail without failing a US-shaped validator.
| Form field | Example | What to test |
|---|---|---|
| Address Line 1 | Flat 4, Ash Court | Do not require a numbered street |
| Address Line 2 | 18 King Street | Allow empty and never insert N/A |
| Post Town | BRISTOL | Keep the postal value supplied with the record |
| County | Keep optional; do not substitute it for Post Town | |
| Postcode | BS1 4DJ | Preserve the normalized internal space |
| Country | GB | Store the code separately from the display label |
A postcode is more than a regular expression
A UK postcode contains an outward code and an inward code separated by a space. A client-side pattern can catch an obvious typo, but it cannot establish that a postcode has been allocated, belongs to the street, or represents a delivery point.
Test raw input, normalized text, and any server-side lookup as separate states. For example, a UI may normalize bs14dj to BS1 4DJ while still making no claim that the generated premises is deliverable.
- Trim leading and trailing whitespace
- Normalize letters to uppercase
- Insert one space before the final three characters
- Use Royal Mail or a licensed address source when a real lookup is required
UK edge cases worth keeping in regression tests
The records most likely to expose a US-centric data model are named premises, multi-line flats, and addresses with no county. Keep these cases in a repeatable regression suite rather than treating them as one-off manual checks.
- A house name instead of a street number
- A flat and building name split across two lines
- A Post Town that differs from the everyday city label
- A valid submission with an empty County field
- A Northern Ireland postcode beginning with BT
Choosing safe UK test data
Format-shaped data is not the same as a deliverable address. For layout and schema tests, label records as synthetic and do not use them for real shipping, account verification, or payment checks.
If a test genuinely requires deliverability, use an address owned by your organization or explicitly authorized for testing. Record the postal lookup result separately from the generated fixture so later readers do not confuse the two.
Frequently asked questions
Is County required in every UK address?
No. Accurate address lines, the Post Town, and postcode are the important postal elements. County may help a person understand the location, but it should remain optional in most international forms.
Can I accept a postcode without its space?
You can accept compact user input, then normalize the display and stored canonical value to one space between the outward and inward parts.
Does a postcode that passes a regex definitely exist?
No. A pattern checks character shape only. It cannot prove allocation, street matching, or delivery-point status.
