diff --git a/README.md b/README.md index d69ce64..c2067c7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -postcode -======== +# postcode (Fork) [![Build Status](https://github.com/adrg/postcode/workflows/CI/badge.svg)](https://github.com/adrg/postcode/actions?query=workflow%3ACI) [![Code coverage](https://codecov.io/gh/adrg/postcode/branch/master/graphs/badge.svg?branch=master)](https://codecov.io/gh/adrg/postcode) [![pkg.go.dev documentation](https://pkg.go.dev/badge/github.com/adrg/postcode)](https://pkg.go.dev/github.com/adrg/postcode) @@ -8,18 +7,16 @@ postcode [![GitHub issues](https://img.shields.io/github/issues/adrg/postcode)](https://github.com/adrg/postcode/issues) [![Buy me a coffee](https://img.shields.io/static/v1.svg?label=%20&message=Buy%20me%20a%20coffee&color=579fbf&logo=buy%20me%20a%20coffee&logoColor=white)](https://ko-fi.com/T6T72WATK) -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. +**Note: This repository is a fork of the original [postcode](https://github.com/adrg/postcode) library. The original repository seems to be inactive, and this fork is actively maintained and updated. Please consider using this fork for any new projects or updates.** -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. +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. -Full documentation can be found at: https://pkg.go.dev/github.com/adrg/postcode. +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 + go get git@github.com:aqibcs/postcode.git ## Usage diff --git a/formats.go b/formats.go index 099569a..7e266dd 100644 --- a/formats.go +++ b/formats.go @@ -7,52 +7,91 @@ package postcode // * N = number // * CC = ISO 3166-1 alpha-2 country code var formats = map[string]struct{}{ - "AA NNNNN": {}, - "AA-NNNN": {}, - "AAA NNNN": {}, - "AAA NNNN-NNNN": {}, - "AAA": {}, - "AAAA NAA": {}, - "AAN NAA": {}, - "AAN": {}, - "AANA": {}, - "AANN NAA": {}, - "AANN NNN": {}, - "AANN": {}, - "AANNNN": {}, - "AN": {}, - "ANA NAN": {}, - "ANA": {}, - "ANN": {}, - "ANNN": {}, - "CC NNNN": {}, - "CC-NNNN": {}, - "CC-NNNNN": {}, - "CCN NAA": {}, - "CCN-NNNN": {}, - "CCNN NAA": {}, - "CCNNN": {}, - "CCNNNN": {}, - "CCNNNNN": {}, - "NN": {}, - "NN-NNN": {}, - "NNN NN": {}, - "NNN NNN": {}, - "NNN": {}, - "NNN-NN": {}, - "NNN-NNNN": {}, - "NNNN NNNN": {}, - "NNNN": {}, - "NNNN-A": {}, - "NNNN-NNN": {}, - "NNNNN": {}, - "NNNNN-NNN": {}, - "NNNNN-NNNN": {}, - "NNNNNN": {}, - "NNNNNNN": {}, - "NNNNNNNNNN": {}, - "NNNNAA": {}, - "NNNN AA": {}, + "AA NNNNN": {}, + "AA-NNNN": {}, + "AAA NNNN": {}, + "AAA NNNN-NNNN": {}, + "AAA": {}, + "AAAA NAA": {}, + "AAN NAA": {}, + "AAN": {}, + "AANA": {}, + "AANN NAA": {}, + "AANN NNN": {}, + "AANN": {}, + "AANNNN": {}, + "AN": {}, + "ANA NAN": {}, + "ANA": {}, + "ANN": {}, + "ANNN": {}, + "CC NNNN": {}, + "CC-NNNN": {}, + "CC-NNNNN": {}, + "CCN NAA": {}, + "CCN-NNNN": {}, + "CCNN NAA": {}, + "CCNNN": {}, + "CCNNNN": {}, + "CCNNNNN": {}, + "NN": {}, + "NN-NNN": {}, + "NNN NN": {}, + "NNN NNN": {}, + "NNN": {}, + "NNN-NN": {}, + "NNN-NNNN": {}, + "NNNN NNNN": {}, + "NNNN": {}, + "NNNN-A": {}, + "NNNN-NNN": {}, + "NNNNN": {}, + "NNNNN-NNN": {}, + "NNNNN-NNNN": {}, + "NNNNNN": {}, + "NNNNNNN": {}, + "NNNNNNNNNN": {}, + "NNNNAA": {}, + "NNNN AA": {}, + "AI-2640": {}, + "BIQQ 1ZZ": {}, + "BBND 1ZZ": {}, + "120000": {}, + "FIQQ 1ZZ": {}, + "CC-NNN": {}, + "973NN": {}, + "987NN": {}, + "A?NNN": {}, + "A?NNNN": {}, + "A?NNNNN": {}, + "GX11 1AA": {}, + "971NN": {}, + "NNNNN-NNNNN": {}, + "972NN": {}, + "976NN": {}, + "980NN": {}, + "MSR NNNN": {}, + "988NN": {}, + "PCRN 1ZZ": {}, + "974NN": {}, + "97133": {}, + "AAAA 1ZZ": {}, + "CCNN NNN": {}, + "97150": {}, + "97500": {}, + "4789N": {}, + "SIQQ 1ZZ": {}, + "NNN-NNN": {}, + "TKCA 1ZZ": {}, + "A[A]N[A/N]": {}, + "96898": {}, + "00120": {}, + "986NN": {}, + "ANNNNAAA": {}, + "AA NN": {}, + "AA AA": {}, + "A[A]N[A/N] NAA": {}, + "[D6W/ANN] [A/N][A/N][A/N][A/N]": {}, } // Source: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 @@ -306,4 +345,5 @@ var countryCodes = map[string]struct{}{ "ZA": {}, "ZM": {}, "ZW": {}, + "XK": {}, } diff --git a/postcode_test.go b/postcode_test.go index ff3c164..159fe92 100644 --- a/postcode_test.go +++ b/postcode_test.go @@ -11,33 +11,28 @@ func TestValidate(t *testing.T) { expected error }{ { - description: "Paris, France", - input: " 75008 ", + description: "Canada, Port Colborne", + input: " L3K 4V9 ", expected: nil, }, { - description: "Brussels, Belgium", - input: " 1000 ", + description: "India , New Delhi", + input: " 110002 ", expected: nil, }, { - description: "Utrecht, The Netherlands", - input: " 3511 ax ", + description: "Mexico, Mexico City", + input: " 01030 ", expected: nil, }, { - description: "Utrecht, The Netherlands, Alt", - input: " 3511AX ", + description: "Japan, Tokyo", + input: " 100-0012 ", expected: nil, }, { - description: "Hannover, Germany", - input: " 30179 ", - expected: nil, - }, - { - description: "Vilnius, Lithuania", - input: "LT-00200", + description: "W N St, Aberdeen AB24, UK", + input: " AB24 ", expected: nil, }, {