UKPostcode

UK postcode parsing, validation and normalisation module.

Source

Summary

full?(postcode)

Returns true or false depending on if the value is a full valid postcode

incode(postcode)

Extracts the right-hand part of the postcode

normalise(postcode)

Returns the canonical string representation of the postcode

outcode(postcode)

Extracts the left-hand part of the postcode

outcode?(postcode)

Returns true or false depending on if the value is a valid left-hand value of a valid postcode

valid?(postcode)

Returns true or false depending on if the value is a valid postcode. This includes both full postcodes and outcode postcodes

Functions

full?(postcode)

Returns true or false depending on if the value is a full valid postcode.

postcode - String postcode

Examples

iex> UKPostcode.full? "W1A 1AA"
true
Source
incode(postcode)

Extracts the right-hand part of the postcode.

postcode - String postcode

Examples

iex> UKPostcode.incode "W1A 1AA"
{:ok, "1AA"}
Source
normalise(postcode)

Returns the canonical string representation of the postcode.

postcode - String postcode

Examples

iex> UKPostcode.normalise "w1a1aa"
"W1A 1AA"
Source
outcode(postcode)

Extracts the left-hand part of the postcode.

postcode - String postcode

Examples

iex> UKPostcode.outcode "W1A 1AA"
{:ok, "W1A"}
Source
outcode?(postcode)

Returns true or false depending on if the value is a valid left-hand value of a valid postcode.

postcode - String postcode

Examples

iex> UKPostcode.outcode? "W1A"
true
Source
valid?(postcode)

Returns true or false depending on if the value is a valid postcode. This includes both full postcodes and outcode postcodes.

postcode - String postcode

Examples

iex> UKPostcode.valid? "W1A 1AA"
true

iex> UKPostcode.valid? "W1A"
true
Source