Validationflags: gi
UK Postcode
Match UK postcodes in the common outward + inward format (e.g. SW1A 1AA, EC1V 9LB).
Try it in RegexProPattern
regexJavaScript
/[A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}/giRaw 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 1AAMatches
SW1A 1AA
Input
EC1V 9LBMatches
EC1V 9LB
Input
B33 8THMatches
B33 8TH
Common use cases
- UK address validation
- Geocoding integration
- Delivery route planning
- Audience targeting by region