Versioned UK postcode QA dataset
UK Postcode Validation Test Suite
A free, deterministic set of 40 postcode syntax and normalisation fixtures for regression tests. Inspect every expected result in HTML, download JSON or CSV, pin version 1.0.1, and verify immutable files before adding them to a build.
By PostcodeLab · Published · Updated
Download the UK postcode validation fixtures
Use the stable URLs when you intentionally want the latest compatible release. Pin the versioned URLs in automated builds so a later release cannot change an assertion unexpectedly.
Latest compatible release: JSON test suite · CSV test suite · integrity manifest · reference crosswalk · crosswalk schema
Pin v1.0.1: versioned JSON · versioned CSV · JSON Schema · versioned SHA-256 manifest · versioned evidence map · evidence-map schema
The files are licensed under CC BY 4.0. Attribute the “PostcodeLab UK Postcode Validation Test Suite” when redistributing the dataset.
Scope: these are labelled syntax fixtures, not postal address records. They contain no person, email, telephone, coordinates or private address dataset fields.
What version 1.0.1 tests
The suite covers the six common outward-code shapes, the special GIR 0AA form, lower-case and spacing recovery, selected pasted punctuation, empty input and deliberately malformed values. Each case has a stable ID and explicit fields rather than a single ambiguous “expected” property.
| Field | Meaning |
|---|---|
expected_status | valid, invalid or empty under the documented PostcodeLab contract. |
expected_normalised | The upper-case, single-space representation produced before syntax classification. |
expected_outward | The outward code only when the syntax result is valid; otherwise an empty string. |
expected_inward | The inward code only when the syntax result is valid; otherwise an empty string. |
| evidence flags | syntax_fixture is true while allocation and deliverability checks are explicitly false. |
Install the offline Node.js QA kit
The versioned developer kit packages all 40 fixtures, the 12-rule evidence crosswalk, JSON Schemas, TypeScript declarations, an observation assessor and a small CLI. It contains no street addresses, names, email addresses, phone numbers or identity records. It has zero runtime dependencies. After installation, its API and CLI perform no network requests, store no telemetry and never execute your validator or regular expression.
npm install --save-dev https://uk.chatgpt.org.uk/downloads/postcodelab-uk-postcode-fixtures-v1.0.1.tgz
Download the v1.0.1 package (30,745 bytes) · SHA-256 checksum file
Package SHA-256: 579ff8097cabadafe56ef30cedb9794e093d3cf5c36d1f5251e605e1232764b0
import {
assessObservations,
getSuite,
verifyBundledArtifacts
} from 'postcodelab-uk-postcode-fixtures';
const integrity = verifyBundledArtifacts();
if (!integrity.passed) throw new Error('Fixture integrity check failed');
const suite = getSuite(); // 40 stable case IDs
const report = assessObservations(observations, { profile: 'full' });
Your own adapter runs the system under test and supplies one observation for every fixture ID. The package compares those observations locally and can emit text, JSON, TAP or JUnit reports. A pass means compatibility with this version of the PostcodeLab syntax contract only; it does not prove postcode allocation, current existence, address association or deliverability.
Licensing: fixture data, schemas and documentation use CC BY 4.0; JavaScript, CLI code, tests and examples use the MIT License. The download is distributed from this canonical page and is not presented as an npm-registry or third-party release.
Use the fixtures in Node, Playwright and Cypress
Compare each field your public validator actually promises. Do not reference a generic testCase.expected property: the schema intentionally uses the four named expected fields below.
Node.js
const response = await fetch('/downloads/uk-postcode-validation-test-suite-v1.0.1.json');
const suite = await response.json();
for (const testCase of suite.cases) {
const actual = validatePostcode(testCase.input);
assert.equal(actual.status, testCase.expected_status);
assert.equal(actual.normalised, testCase.expected_normalised);
assert.equal(actual.outward, testCase.expected_outward);
assert.equal(actual.inward, testCase.expected_inward);
}
Playwright
const response = await request.get('/downloads/uk-postcode-validation-test-suite-v1.0.1.json');
const { cases } = await response.json();
for (const testCase of cases) {
test(testCase.id, async ({ page }) => {
await page.getByLabel('UK postcode').fill(testCase.input);
await page.getByRole('button', { name: 'Check and format' }).click();
await expect(page.getByTestId('status')).toHaveText(testCase.expected_status);
await expect(page.getByTestId('normalised')).toHaveText(testCase.expected_normalised);
});
}
Cypress
cy.request('/downloads/uk-postcode-validation-test-suite-v1.0.1.json').then(({ body }) => {
body.cases.forEach((testCase) => {
cy.get('[name="postcode"]').clear().type(testCase.input || ' ');
cy.get('[type="submit"]').click();
cy.get('[data-testid="status"]').should('have.text', testCase.expected_status);
cy.get('[data-testid="normalised"]').should('have.text', testCase.expected_normalised);
});
});
Adapt selectors to your interface and preserve the distinction between an empty value and invalid syntax. The UK postcode regex guide and compatibility runner explain how the default pattern behaves after normalisation.
Verify immutable downloads with SHA-256
The integrity manifest records the byte length, media type and SHA-256 digest of the versioned JSON, CSV, suite schema, reference crosswalk and crosswalk schema. It does not list itself, avoiding a recursive checksum. Download both the pinned file and manifest v1.0.1, calculate the digest locally, then compare exact lower-case hexadecimal values before accepting an update.
import { createHash } from 'node:crypto';
const bytes = Buffer.from(await (await fetch(file.url)).arrayBuffer());
const actual = createHash('sha256').update(bytes).digest('hex');
if (actual !== file.sha256 || bytes.length !== file.byte_length) {
throw new Error('Postcode fixture integrity check failed');
}
The manifest status means the published bytes were measured for the production origin. It does not certify the postal meaning of a fixture or replace your dependency review process.
Browse all 40 UK postcode test cases
This server-rendered catalogue makes the complete contract inspectable without downloading a file or running JavaScript. Inputs are test strings; examples that resemble familiar postcodes demonstrate syntax only.
| Case ID | Category | Input | Expected status | Expected normalised | Purpose | Evidence |
|---|---|---|---|---|---|---|
shape-an-naa |
valid shape | M1 1AA |
valid |
M1 1AA |
AN NAA structure | Evidence |
shape-ann-naa |
valid shape | M60 1NW |
valid |
M60 1NW |
ANN NAA structure | Evidence |
shape-aan-naa |
valid shape | CR2 6XH |
valid |
CR2 6XH |
AAN NAA structure | Evidence |
shape-aann-naa |
valid shape | DN55 1PT |
valid |
DN55 1PT |
AANN NAA structure | Evidence |
shape-ana-naa |
valid shape | W1A 1HQ |
valid |
W1A 1HQ |
ANA NAA structure | Evidence |
shape-aana-naa |
valid shape | EC1A 1BB |
valid |
EC1A 1BB |
AANA NAA structure | Evidence |
shape-gir-special |
valid shape | GIR 0AA |
valid |
GIR 0AA |
Special GIR 0AA syntax | Evidence |
normalise-lowercase |
normalisation | sw1a 1aa |
valid |
SW1A 1AA |
Lower-case input | Evidence |
normalise-no-space |
normalisation | EC1A1BB |
valid |
EC1A 1BB |
Missing separator space | Evidence |
normalise-outer-space |
normalisation | B33 8TH |
valid |
B33 8TH |
Leading and trailing whitespace | Evidence |
normalise-repeated-space |
normalisation | DN55 1PT |
valid |
DN55 1PT |
Repeated internal whitespace | Evidence |
normalise-parentheses |
normalisation | EC1A (1BB) |
valid |
EC1A 1BB |
Common pasted parentheses | Evidence |
normalise-dash-and-dot |
normalisation | G-I-R. 0AA |
valid |
GIR 0AA |
Common pasted dash and full stop | Evidence |
normalise-en-dash |
normalisation | S–W1A 1AA |
valid |
SW1A 1AA |
Pasted typographic dash | Evidence |
empty-string |
empty | [empty string] |
empty |
[empty] |
No input | Evidence |
empty-whitespace |
empty | [3 spaces] |
empty |
[empty] |
Whitespace-only input | Evidence |
invalid-too-short |
invalid | M1AA |
invalid |
M 1AA |
Too few characters | Evidence |
invalid-too-long |
invalid | EC1A 11BBB |
invalid |
EC1A11 BBB |
Too many characters | Evidence |
invalid-slash |
invalid | SW1A/1AA |
invalid |
SW1A/ 1AA |
Unsupported punctuation | Evidence |
invalid-inward-i |
invalid | SW1A 1AI |
invalid |
SW1A 1AI |
Disallowed inward-code letter I | Evidence |
invalid-inward-c |
invalid | SW1A 1AC |
invalid |
SW1A 1AC |
Disallowed inward-code letter C | Evidence |
invalid-inward-v |
invalid | SW1A 1AV |
invalid |
SW1A 1AV |
Disallowed inward-code letter V | Evidence |
invalid-inward-start-letter |
invalid | SW1A AAB |
invalid |
SW1A AAB |
Inward code must start with a digit | Evidence |
invalid-outward-start-digit |
invalid | 1W1A 1AA |
invalid |
1W1A 1AA |
Outward code must start with a letter | Evidence |
invalid-outward-district |
invalid | ECBA 1BB |
invalid |
ECBA 1BB |
Invalid outward district position | Evidence |
invalid-first-alpha-q |
invalid | Q1 1AA |
invalid |
Q1 1AA |
Q is not used in the first alpha position | Evidence |
invalid-first-alpha-v |
invalid | V1 1AA |
invalid |
V1 1AA |
V is not used in the first alpha position | Evidence |
invalid-first-alpha-x |
invalid | X1 1AA |
invalid |
X1 1AA |
X is not used in the first alpha position | Evidence |
invalid-second-alpha-i |
invalid | AI1 1AA |
invalid |
AI1 1AA |
I is not used in the second alpha position | Evidence |
invalid-second-alpha-j |
invalid | AJ1 1AA |
invalid |
AJ1 1AA |
J is not used in the second alpha position | Evidence |
invalid-second-alpha-z |
invalid | AZ1 1AA |
invalid |
AZ1 1AA |
Z is not used in the second alpha position | Evidence |
invalid-third-alpha-l |
invalid | A1L 1AA |
invalid |
A1L 1AA |
L is not permitted as the third outward-position letter | Evidence |
invalid-fourth-alpha-c |
invalid | AB1C 1AA |
invalid |
AB1C 1AA |
C is not permitted as the fourth outward-position letter | Evidence |
invalid-inward-missing-letter |
invalid | M1 1A |
invalid |
M 11A |
Incomplete inward code | Evidence |
invalid-inward-extra-letter |
invalid | M1 1AAA |
invalid |
M11 AAA |
Overlong inward code | Evidence |
invalid-bfpo |
invalid | BFPO 123 |
invalid |
BFPO 123 |
BFPO is outside this validator contract | Evidence |
invalid-all-digits |
invalid | 12345 |
invalid |
12 345 |
Letters are missing | Evidence |
invalid-free-text |
invalid | NOT A POSTCODE |
invalid |
NOTAPOSTC ODE |
Free text is not a postcode | Evidence |
invalid-symbol |
invalid | SW1A@1AA |
invalid |
SW1A@ 1AA |
Unsupported character | Evidence |
invalid-numeric-tail |
invalid | SW1A 111 |
invalid |
SW1A 111 |
Inward code must end with permitted letters | Evidence |
How the syntax contract relates to published guidance
The test design draws on published postcode structure and letter-position guidance, then adds an explicitly labelled PostcodeLab normalisation policy for common pasted input. This is an independent compatibility dataset, not a Royal Mail, ONS or GOV.UK product or certification.
| Fixture group | What it supports | What it does not prove |
|---|---|---|
| Valid shapes | Common outward/inward structures and published letter-position rules. | That the example is currently allocated or deliverable. |
| Normalisation | PostcodeLab's documented recovery of case, spacing and selected punctuation. | That another implementation should accept identical punctuation. |
| Invalid syntax | Boundary checks for length, position, characters and unsupported BFPO input. | Exhaustive rejection of every possible malformed string. |
| Empty input | A distinct empty state that forms can handle accessibly. | Any rule about whether a business field is mandatory. |
Official-reference evidence map
The evidence map connects every fixture ID to exactly one documented rule, identifies whether its claim comes from published guidance or the PostcodeLab contract, and records what the evidence does not prove. Source links provide support, context or a deliberate contrast; they do not turn this independent suite into an official test product.
| Rule | Provenance | Sources | Cases | Supports | Does not prove |
|---|---|---|---|---|---|
Common outward and inward formatscommon-outward-and-inward-formats |
Published guidance | Royal Mail (Section 2.2, pages 10–11) Office for National Statistics (Postcode structure; Limitations of using postcodes as a geographic reference) |
6 | Six documented outward-code shapes followed by a three-character inward code. | That any example is allocated, current, address-matched or deliverable. |
GIR 0AA special casegir-special-case |
Published guidance | Royal Mail (Section 2.2, pages 10–11) | 1 | The documented historic GIR 0AA exception. | A general rule for other three-letter outward codes. |
First outward letter exclusionsfirst-outward-letter-exclusions |
Published guidance | Royal Mail (Section 2.2, pages 10–11) | 3 | Published first alpha-position exclusions. | Current allocation of a syntactically permitted area. |
Second outward letter exclusionssecond-outward-letter-exclusions |
Published guidance | Royal Mail (Section 2.2, pages 10–11) | 3 | Published second alpha-position exclusions. | Current allocation of a syntactically permitted area. |
Third outward letter policythird-outward-letter-policy |
Published guidance | Royal Mail (Section 2.2, pages 10–11) | 1 | Published permitted letters for the third outward position. | Every service's complete postcode validation policy. |
Fourth outward letter PostcodeLab policyfourth-outward-letter-postcodelab-policy |
PostcodeLab contract | Royal Mail (Section 2.2, pages 10–11) | 1 | The stricter fourth-position rule implemented by the PostcodeLab syntax contract. | That the cited guide publishes a complete fourth-position letter set or that this is universal. |
Inward code structure and lettersinward-code-structure-and-letters |
Published guidance | Royal Mail (Section 2.2, pages 10–11) Office for National Statistics (Postcode structure; Limitations of using postcodes as a geographic reference) |
7 | A three-character inward code beginning with a digit and using the documented letter set. | Allocation, current existence, address association or deliverability. |
Human-input normalisationhuman-input-normalisation |
PostcodeLab contract | GOV.UK Design System (Allow different postcode formats) GOV.UK Design System (How it works; Client side and server side validation) |
7 | User-centred recovery of case, spacing and common pasted punctuation, with exact outputs defined by PostcodeLab. | That every implementation must apply the same transformations or accept ambiguous input. |
Empty input stateempty-input-state |
PostcodeLab contract | GOV.UK Design System (How it works; Client side and server side validation) | 2 | A distinct empty state under this suite's form-validation contract. | Whether a postcode is mandatory in another service. |
Malformed structure boundariesmalformed-structure-boundaries |
PostcodeLab contract | Royal Mail (Section 2.2, pages 10–11) Office for National Statistics (Postcode structure; Limitations of using postcodes as a geographic reference) |
6 | Boundary cases outside the documented alphanumeric outward/inward structure under the PostcodeLab contract. | Exhaustive rejection of every malformed string. |
Unsupported character policyunsupported-character-policy |
PostcodeLab contract | GOV.UK Design System (Allow different postcode formats) GOV.UK Design System (How it works; Client side and server side validation) |
2 | PostcodeLab handling of characters outside its selected recoverable punctuation set. | That slash or every symbol is universally invalid; GOV.UK recommends tolerating unambiguous unwanted characters. |
BFPO out of scopebfpo-out-of-scope |
PostcodeLab contract | Education and Skills Funding Agency (Appendix D.2, page 77) | 1 | BFPO is deliberately outside the PostcodeLab suite contract, while an official service-specific contract demonstrates that BFPO policies can differ. | That BFPO is universally invalid. |
Download the versioned machine-readable crosswalk and its JSON Schema to audit the complete 40/40 case mapping in CI.
Version history and validation limits
| Version | Published | Change |
|---|---|---|
| 1.0.1 | 12 August 2026 | Metadata-only provenance release: gives the dataset its dedicated landing page and implementation-guide link, adds the official-reference crosswalk, and leaves all 40 cases and CSV rows unchanged. |
| 1.0.0 | 12 August 2026 | Initial public JSON and CSV fixture set with JSON Schema and a production-origin integrity manifest. Its immutable metadata is retained for reproducibility. |
The versioned URLs are immutable. Stable paths can point to a later compatible release, so review the manifest and release notes before updating a pinned suite.
- A valid syntax result does not prove allocation, current existence, deliverability or a relationship with any address or identity.
- The suite documents the PostcodeLab contract; it is not an exhaustive catalogue of every postcode system or provider policy.
- BFPO and formats outside the documented checker contract are intentionally unsupported in version 1.0.1.
- Use a maintained authoritative directory or licensed address product when your decision needs current existence or address-level verification.
Official references
Related developer guides
UK Postcode Regex and Validation Examples
Build a maintainable UK postcode regex with normalisation, JavaScript examples, valid format cases, server-side checks and clear validation limits.
Read guideUK Postcode Format and Validation Guide
Understand UK postcode structure, outward and inward codes, normalisation, syntax validation, lookup checks and practical QA test cases.
Read guideUK Address Form Test Cases and QA Checklist
Use practical UK address form test cases for field variation, postcodes, lookup failure, accessibility, mobile layouts, exports and integration safety.
Read guidePostcode Validation vs Address Verification
Compare postcode syntax validation, postcode lookup, address verification, UPRN matching and deliverability checks when designing UK forms and tests.
Read guide