Skip to main content
AllDevToolsHub
Back to all patterns

UK Postal Code

Validation

Validates a UK postal code (postcode) with optional space.

/^[A-Z]{1,2}[0-9][A-Z0-9]? ?[0-9][A-Z]{2}$/i

How it works

UK postcodes are alphanumeric, divided into outward (1–2 letters + 1 digit + optional letter/digit) and inward (1 digit + 2 letters) parts. The space between parts is conventional but optional.

Test Cases

Should Match

  • SW1A 1AA
  • EC1A1BB
  • W1A 0AX
  • M1 1AE
  • B33 8TH

Should NOT Match

  • 12345
  • ABCDE
  • SW1A1A

Quick Summary

Validates a UK postcode (e.g., SW1A 1AA). The space between outward and inward parts is optional.