postcode: github.com/adrg/postcode Index | Files

package postcode

import "github.com/adrg/postcode"

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:
https://en.wikipedia.org/wiki/List_of_postal_codes
https://en.wikipedia.org/wiki/ISO_3166-1

Example

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

Index

Package Files

formats.go postcode.go

Variables

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.