postcode: Index | Files

package postcode

import ""

Package postcode validates postal codes. While the validation process does not guarantee that the postcode actually exists, it does guarantee that the format of the provided input is valid.

For more information see:


if err := postcode.Validate("10007"); err != nil {
	// the postcode is not valid
	// treat error


Package Files

formats.go postcode.go


var (
    ErrEmpty          = errors.New("postal code cannot be empty")
    ErrShort          = errors.New("postal code cannot be shorter than 2 characters")
    ErrInvalidCountry = errors.New("invalid country code")
    ErrInvalidFormat  = errors.New("invalid postal code format")

Possible validation errors.

func Validate Uses

func Validate(code string) error

Validate checks if the provided input string matches any of the accepted postcode formats. If the validation fails, the function returns an error specifying the cause.

Package postcode imports 3 packages (graph). Updated 2020-10-14. Refresh now. Tools for package owners.