Validationflags: gi

UK Postcode

Match UK postcodes in the common outward + inward format (e.g. SW1A 1AA, EC1V 9LB).

Try it in RegexPro

Pattern

regexJavaScript
/[A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}/gi

Raw source: [A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}

How it works

1–2 letters, 1 digit, optional letter/digit, optional space, 1 digit, 2 letters. Case-insensitive flag handles lower and mixed case input.

Examples

Input

SW1A 1AA

Matches

  • SW1A 1AA

Input

EC1V 9LB

Matches

  • EC1V 9LB

Input

B33 8TH

Matches

  • B33 8TH

Common use cases

  • UK address validation
  • Geocoding integration
  • Delivery route planning
  • Audience targeting by region