Nuclear Pumpkin Mocha

    uk-postcode-validator
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.1 • Public • Published

    uk-postcode-validator npm size Build Status

    Validate UK postcodes.

    Installation

    $ npm install uk-postcode-validator

    Example

    import isValid from "uk-postcode-validator";
    // or const isValid = require("uk-postcode-validator").default;
     
    isValid("N7 7AJ");
    //=> true
     
    isValid("N77AJ");
    //=> true
     
    isValid("GIR 0AA");
    //=> true
     
    isValid("N7 A7J");
    //=> false
     
    isValid("90210");
    //=> false

    API

    isValid(input)

    Returns the true or false based on the postcode validity.

    input

    Type: string

    Logic

        "GIR 0AA"
    OR
        One letter followed by either one or two numbers
    OR
        One letter followed by a second letter that must be one of ABCDEFGHJKLMNOPQRSTUVWXY (i.e..not I) and then followed by either one or two numbers
    OR
        One letter followed by one number and then another letter
    OR
        A two part post code where the first part must be One letter followed by a second letter that must be one of ABCDEFGHJKLMNOPQRSTUVWXY (i.e..not I) and then followed by one number and optionally a further letter after that
        AND
        The second part must be One number followed by two letters.

    A combination of upper and lower case characters is allowed.

    The length is determined by the regular expression and is between 2 and 8 characters.

    Inspired by

    This stack overflow discussion and this gov.uk document.

    Install

    npm i uk-postcode-validator

    DownloadsWeekly Downloads

    329

    Version

    1.1.1

    License

    MIT

    Unpacked Size

    192 kB

    Total Files

    14

    Last publish

    Collaborators

    • sirlisko