Skip to the content

address-plusアドレスプラス

Parse, validate, format and compare addresses locally, add country modules and mount an optional native form field.

address-plus extends the parse-address style with typed results, validation, formatting and country modules. About the name

Contents

Reference · British country module

isValidUKPostcodefunction

Whether a postcode follows Royal Mail's grammar: one of the six shapes (M2 5BQ, M34 4AB, CR0 2YR, DN16 9AA, W1A 4ZZ, EC1A 1HQ) with the letters each place allows, or GIR 0AA. Letter case and the space do not matter. Whether the postcode is in use is a different question; parseUKPostcode and the validator also check its area and district.

Import it

import { isValidUKPostcode } from "@johnmorrisdotca/address-plus/gb";

Definition

function isValidUKPostcode(postcode: string): boolean

Parameters

NameTypeDescription
postcodestring

The postcode.

Returns

boolean

true when it has a postcode's shape and letters.

Examples

import { isValidUKPostcode } from "@johnmorrisdotca/address-plus/gb";

console.log(["EC1A 1BB", "sw1a1aa", "GIR 0AA", "Q1 1AA", "M5V 1A1"].map(isValidUKPostcode));
// → [true,true,true,false,false]
[ true, true, true, false, false ]

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/address-plus 1.7.0.