|
9 | 9 | /** |
10 | 10 | * Validates and formats the postcodes in the Republic of Ireland. |
11 | 11 | * |
12 | | - * Postcodes can have eight different formats: |
| 12 | + * Postcodes can have at least the following thirteen different formats: |
13 | 13 | * |
14 | | - * - ANN ANAN |
15 | | - * - ANN AANN |
| 14 | + * - ANN NNNA |
| 15 | + * - ANN NANN |
16 | 16 | * - ANN ANNN |
| 17 | + * - ANN ANNA |
| 18 | + * - ANN ANAN |
17 | 19 | * - ANN ANAA |
| 20 | + * - ANN AANN |
| 21 | + * - ANN AANA |
| 22 | + * - ANN AAAN |
18 | 23 | * |
19 | | - * - ANW ANAN |
20 | | - * - ANW AANN |
21 | | - * - ANW ANAA |
22 | | - * - ANW ANNN (?) @todo ANNN is valid with ANN prefix, but not sure about ANW. |
| 24 | + * - D6W ANAN |
| 25 | + * - D6W AANN |
| 26 | + * - D6W ANAA |
| 27 | + * - D6W ANNN |
23 | 28 | * |
24 | | - * A stands for a capital letter, N stands for a digit, W is the letter W. |
| 29 | + * A stands for the capital letter A,C,D,E,F,H,K,N,P,R,T,V,W,X or Y. N stands for a digit. D6W stans literally for D6W. |
25 | 30 | * |
26 | | - * @todo not all alphabet letters are allowed. |
| 31 | + * The first part is one of the 139 Routing Keys, the second is a Unique Identifier. |
| 32 | + * The pdf document linked below defines Eircode's character set on page 11. |
27 | 33 | * |
28 | 34 | * @see https://en.wikipedia.org/wiki/List_of_postal_codes |
29 | 35 | * @see https://en.wikipedia.org/wiki/Postal_addresses_in_the_Republic_of_Ireland |
30 | | - * @see https://www.eircode.ie/ |
| 36 | + * @see https://www.eircode.ie/docs/default-source/Common/prepareyourbusinessforeircode-edition3published.pdf |
| 37 | + * @see https://www.autoaddress.ie/support/developer-centre/resources/routing-key-boundaries |
31 | 38 | */ |
32 | 39 | class IEFormatter implements CountryPostcodeFormatter |
33 | 40 | { |
34 | 41 | /** |
35 | 42 | * The regular expression pattern used to validate the postcode and extract the two parts. |
36 | 43 | */ |
37 | 44 | private const PATTERN = '/^' |
38 | | - . '([A-Z][0-9][0-9W])' |
39 | 45 | . '(' |
40 | | - . '(?:[A-Z][0-9][0-9][0-9])|' |
41 | | - . '(?:[A-Z][0-9][A-Z][0-9])|' |
42 | | - . '(?:[A-Z][A-Z][0-9][0-9])|' |
43 | | - . '(?:[A-Z][0-9][A-Z][A-Z])' |
| 46 | + . 'A41|A42|A45|A63|A67|A75|A81|A82|A83|A84|A85|A86|A91|A92|A94|A96|A98|C15|D01|D02|D03|D04|D05|D06|D6W|D07|D08|D09|' |
| 47 | + . 'D10|D11|D12|D13|D14|D15|D16|D17|D18|D20|D22|D24|E21|E25|E32|E34|E41|E45|E53|E91|F12|F23|F26|F28|F31|F35|F42|F45|' |
| 48 | + . 'F52|F56|F91|F92|F93|F94|H12|H14|H16|H18|H23|H53|H54|H62|H65|H71|H91|K32|K34|K36|K45|K56|K67|K78|N37|N39|N41|N91|' |
| 49 | + . 'P12|P14|P17|P24|P25|P31|P32|P36|P43|P47|P51|P56|P61|P67|P72|P75|P81|P85|R14|R21|R32|R35|R42|R45|R51|R56|R93|R95|' |
| 50 | + . 'T12|T23|T34|T45|T56|V14|V15|V23|V31|V35|V42|V92|V93|V94|V95|W12|W23|W34|W91|X35|X42|X91|Y14|Y21|Y25|Y34|Y35' |
44 | 51 | . ')' |
| 52 | + . '([ACDEFHKNPRTVWXY0-9]{4})' |
45 | 53 | . '$/'; |
46 | 54 |
|
47 | 55 | /** |
|
0 commit comments