Launching a SaaS?·Collect waitlist signups before you build — before.run
SandboxPatternsDetectDocsChangelog
Address
en-GB
#postcode
#postal
#uk
#british

UK Postcode

Matches a UK postcode in the standard format (e.g. SW1A 1AA, EC1A 1BB).

UK address formsDelivery validationGeographic targeting
/
/
Safe
Test String
5 matches
[…]{1,2}Character class […]Matches any single character listed in this set — repeated between 1 and 2 times · {1,2} — between 1 and 2 times
A-ZA-ZA-Z — range from 'A' to 'Z'
\ddigit\d — digit (0–9)
[…]?Character class […]Matches any single character listed in this set — repeated zero or one time (optional) · ? — zero or one time (optional)
A-ZA-ZA-Z — range from 'A' to 'Z'
\ddigit\d — digit (0–9)
\s?space\s — whitespace (space, tab, newline…) — repeated zero or one time (optional) · ? — zero or one time (optional)
\ddigit\d — digit (0–9)
[…]{2}Character class […]Matches any single character listed in this set — repeated exactly 2 times · {2} — exactly 2 times
A-ZA-ZA-Z — range from 'A' to 'Z'
Pattern: 33 charsInput: 40 chars
100% client-side · private

Valid Examples

  • SW1A 1AA
  • EC1A 1BB
  • W1A 0AX
  • M1 1AE
  • SW1A1AA

Invalid Examples

  • 123 456
  • ABCD 1EF
  • SW1A 1A

Usage & Integration

Validate UK Postcode natively in your backend or frontend without copying regex strings.

Node / Edge

import { validate } from '@regexto/validators';

validate('uk-postcode', '...');

Python

from regexto_validators import validate

validate("uk-postcode", "...")

Go

import "github.com/regex-to/validators-go"

valid, err := validators.Validate("uk-postcode", "...")

PHP

use RegexTo\Validators\Validator;

Validator::validate('uk-postcode', '...');

Rust

use regexto_validators::validate;

let is_valid = validate("uk-postcode", "...").unwrap();