postcode

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2020 License: MIT Imports: 3 Imported by: 4

README

postcode

Build Status Code coverage pkg.go.dev documentation Go Report Card

Small package for validating 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.

The reason for creating this package is that there is no good regular expression for validating postal codes, and even if it existed, it would have been huge and inefficient.

Full documentation can be found at: https://godoc.org/github.com/adrg/postcode

Installation

go get github.com/adrg/postcode

Usage

package main

import (
	"github.com/adrg/postcode"
)

func main() {
    if err := postcode.Validate("10007"); err != nil {
        // Treat error.
    }
}

References

For more information see

Contributing

Contributions in the form of pull requests, issues or just general feedback, are always welcome. See CONTRIBUTING.MD.

License

Copyright (c) 2016 Adrian-George Bostan.

This project is licensed under the MIT license. See LICENSE for more details.

Documentation

Overview

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

Constants

This section is empty.

Variables

View Source
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.

Functions

func Validate

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL