npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

uk-postcode-validator

v2.0.0

Published

Validate UK postcodes.

Readme

uk-postcode-validator

npm license

Check whether a string is a correctly formatted UK postcode.

  • Checks every position. Each position only accepts the letters used in real postcodes, so Q1 1AA or N7 7CA are rejected.
  • Forgiving with input. Case-insensitive, with or without the space, and surrounding whitespace is ignored.
  • Tiny. One function, no dependencies.
  • Typed. TypeScript declarations included.

Install

npm install uk-postcode-validator

Usage

import { isValid } from "uk-postcode-validator";
// or const { isValid } = require("uk-postcode-validator");

isValid("N7 7AJ"); // true
isValid("n77aj"); // true
isValid(" EC1A 1BB "); // true
isValid("GIR 0AA"); // true

isValid("N7 A7J"); // false
isValid("Q1 1AA"); // false
isValid("90210"); // false

API

| Import | Value | | ------------------------------------ | --------------------------------------------------------- | | isValid(postcode: string): boolean | true if postcode is a correctly formatted UK postcode | | default | The same isValid function |

Validation rules

A postcode is an outward code followed by an inward code, optionally separated by whitespace. GIR 0AA is also accepted.

Outward code, one of:  A9  A99  AA9  AA99  A9A  AA9A
Inward code:           9AA

1st position:  any letter except Q, V, X
2nd position:  any letter except I, J, Z
3rd position:  (A9A) only A, B, C, D, E, F, G, H, J, K, P, S, T, U, W
4th position:  (AA9A) only A, B, E, H, M, N, P, R, V, W, X, Y
Inward code:   letters except C, I, K, M, O, V

It checks the format only, not whether the postcode exists. For that, look it up against a dataset such as the ONS Postcode Directory.

Not included: BFPO addresses, overseas territories (e.g. ASCN 1ZZ, KY1-1001) and pseudo-postcodes such as ZZ99 9ZZ.

Migrating from 1.x

  • Validation is stricter. Text around a postcode ("GIR0AA nonsense") and letters not used in a given position ("Q1 1AA", "ZZ99 9ZZ") are now rejected.
  • With require, use the named export: const { isValid } = require("uk-postcode-validator") instead of .default. The default export still works.
  • The build targets ES2017, so very old browsers need it transpiled.

Contributing

pnpm install
pnpm test

Credits

Validation rules from BS 7666, as summarised in Postcodes in the United Kingdom on Wikipedia.

License

MIT © Luca Lischetti