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]?\d{3}$`,
26 "PT": `^\d{4}([\-]\d{3})?$`,
27 "FI": `^\d{5}$`,
28 "AX": `^22\d{3}$`,
29 "KR": `^\d{3}[\-]\d{3}$`,
30 "CN": `^\d{6}$`,
31 "TW": `^\d{3}(\d{2})?$`,
32 "SG": `^\d{6}$`,
33 "DZ": `^\d{5}$`,
34 "AD": `^AD\d{3}$`,
35 "AR": `^([A-HJ-NP-Z])?\d{4}([A-Z]{3})?$`,
36 "AM": `^(37)?\d{4}$`,
37 "AZ": `^\d{4}$`,
38 "BH": `^((1[0-2]|[2-9])\d{2})?$`,
39 "BD": `^\d{4}$`,
40 "BB": `^(BB\d{5})?$`,
41 "BY": `^\d{6}$`,
42 "BM": `^[A-Z]{2}[ ]?[A-Z0-9]{2}$`,
43 "BA": `^\d{5}$`,
44 "IO": `^BBND 1ZZ$`,
45 "BN": `^[A-Z]{2}[ ]?\d{4}$`,
46 "BG": `^\d{4}$`,
47 "KH": `^\d{5}$`,
48 "CV": `^\d{4}$`,
49 "CL": `^\d{7}$`,
50 "CR": `^\d{4,5}|\d{3}-\d{4}$`,
51 "HR": `^\d{5}$`,
52 "CY": `^\d{4}$`,
53 "CZ": `^\d{3}[ ]?\d{2}$`,
54 "DO": `^\d{5}$`,
55 "EC": `^([A-Z]\d{4}[A-Z]|(?:[A-Z]{2})?\d{6})?$`,
56 "EG": `^\d{5}$`,
57 "EE": `^\d{5}$`,
58 "FO": `^\d{3}$`,
59 "GE": `^\d{4}$`,
60 "GR": `^\d{3}[ ]?\d{2}$`,
61 "GL": `^39\d{2}$`,
62 "GT": `^\d{5}$`,
63 "HT": `^\d{4}$`,
64 "HN": `^(?:\d{5})?$`,
65 "HU": `^\d{4}$`,
66 "IS": `^\d{3}$`,
67 "IN": `^\d{6}$`,
68 "ID": `^\d{5}$`,
69 "IL": `^\d{5}$`,
70 "JO": `^\d{5}$`,
71 "KZ": `^\d{6}$`,
72 "KE": `^\d{5}$`,
73 "KW": `^\d{5}$`,
74 "LA": `^\d{5}$`,
75 "LV": `^\d{4}$`,
76 "LB": `^(\d{4}([ ]?\d{4})?)?$`,
77 "LI": `^(948[5-9])|(949[0-7])$`,
78 "LT": `^\d{5}$`,
79 "LU": `^\d{4}$`,
80 "MK": `^\d{4}$`,
81 "MY": `^\d{5}$`,
82 "MV": `^\d{5}$`,
83 "MT": `^[A-Z]{3}[ ]?\d{2,4}$`,
84 "MU": `^(\d{3}[A-Z]{2}\d{3})?$`,
85 "MX": `^\d{5}$`,
86 "MD": `^\d{4}$`,
87 "MC": `^980\d{2}$`,
88 "MA": `^\d{5}$`,
89 "NP": `^\d{5}$`,
90 "NZ": `^\d{4}$`,
91 "NI": `^((\d{4}-)?\d{3}-\d{3}(-\d{1})?)?$`,
92 "NG": `^(\d{6})?$`,
93 "OM": `^(PC )?\d{3}$`,
94 "PK": `^\d{5}$`,
95 "PY": `^\d{4}$`,
96 "PH": `^\d{4}$`,
97 "PL": `^\d{2}-\d{3}$`,
98 "PR": `^00[679]\d{2}([ \-]\d{4})?$`,
99 "RO": `^\d{6}$`,
100 "RU": `^\d{6}$`,
101 "SM": `^4789\d$`,
102 "SA": `^\d{5}$`,
103 "SN": `^\d{5}$`,
104 "SK": `^\d{3}[ ]?\d{2}$`,
105 "SI": `^\d{4}$`,
106 "ZA": `^\d{4}$`,
107 "LK": `^\d{5}$`,
108 "TJ": `^\d{6}$`,
109 "TH": `^\d{5}$`,
110 "TN": `^\d{4}$`,
111 "TR": `^\d{5}$`,
112 "TM": `^\d{6}$`,
113 "UA": `^\d{5}$`,
114 "UY": `^\d{5}$`,
115 "UZ": `^\d{6}$`,
116 "VA": `^00120$`,
117 "VE": `^\d{4}$`,
118 "ZM": `^\d{5}$`,
119 "AS": `^96799$`,
120 "CC": `^6799$`,
121 "CK": `^\d{4}$`,
122 "RS": `^\d{6}$`,
123 "ME": `^8\d{4}$`,
124 "CS": `^\d{5}$`,
125 "YU": `^\d{5}$`,
126 "CX": `^6798$`,
127 "ET": `^\d{4}$`,
128 "FK": `^FIQQ 1ZZ$`,
129 "NF": `^2899$`,
130 "FM": `^(9694[1-4])([ \-]\d{4})?$`,
131 "GF": `^9[78]3\d{2}$`,
132 "GN": `^\d{3}$`,
133 "GP": `^9[78][01]\d{2}$`,
134 "GS": `^SIQQ 1ZZ$`,
135 "GU": `^969[123]\d([ \-]\d{4})?$`,
136 "GW": `^\d{4}$`,
137 "HM": `^\d{4}$`,
138 "IQ": `^\d{5}$`,
139 "KG": `^\d{6}$`,
140 "LR": `^\d{4}$`,
141 "LS": `^\d{3}$`,
142 "MG": `^\d{3}$`,
143 "MH": `^969[67]\d([ \-]\d{4})?$`,
144 "MN": `^\d{6}$`,
145 "MP": `^9695[012]([ \-]\d{4})?$`,
146 "MQ": `^9[78]2\d{2}$`,
147 "NC": `^988\d{2}$`,
148 "NE": `^\d{4}$`,
149 "VI": `^008(([0-4]\d)|(5[01]))([ \-]\d{4})?$`,
150 "VN": `^[0-9]{1,6}$`,
151 "PF": `^987\d{2}$`,
152 "PG": `^\d{3}$`,
153 "PM": `^9[78]5\d{2}$`,
154 "PN": `^PCRN 1ZZ$`,
155 "PW": `^96940$`,
156 "RE": `^9[78]4\d{2}$`,
157 "SH": `^(ASCN|STHL) 1ZZ$`,
158 "SJ": `^\d{4}$`,
159 "SO": `^\d{5}$`,
160 "SZ": `^[HLMS]\d{3}$`,
161 "TC": `^TKCA 1ZZ$`,
162 "WF": `^986\d{2}$`,
163 "XK": `^\d{5}$`,
164 "YT": `^976\d{2}$`,
165 }
166
167 var postCodeRegexDict = map[string]*regexp.Regexp{}
168
169 func init() {
170 for countryCode, pattern := range postCodePatternDict {
171 postCodeRegexDict[countryCode] = regexp.MustCompile(pattern)
172 }
173 }
174
View as plain text