# \[Globalize\] Enhancement - zip code regexes for each country

**URL:** <https://www.ruby-forum.com/t/globalize-enhancement-zip-code-regexes-for-each-country/60293>\
**Category:** Rails\
**Created:** [May 11, 2006, 10:06pm UTC](https://www.ruby-forum.com/t/globalize-enhancement-zip-code-regexes-for-each-country/60293 "2006-05-11T22:06:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghulette](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/51bf81/32.png) [@ghulette](https://www.ruby-forum.com/u/ghulette)\
**Post date:** [May 11, 2006, 10:06pm UTC](https://www.ruby-forum.com/t/globalize-enhancement-zip-code-regexes-for-each-country/60293/1 "2006-05-11T22:06:37Z")

</div>

Was just playing around with trying to sort out validation of  
zip/postcodes  
depending on what country the user lived in, and was wondering if anyone  
has  
done this in a nice way? Seems to me that it would be a relatively  
simple  
addition to Globalize to add a regex for zip code validation to the  
things  
already in there?

Or am I missing a trick?  
Thanks  
geoff

---

<div class="post-metadata">

**Author:** ![ghulette](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/51bf81/32.png) [@ghulette](https://www.ruby-forum.com/u/ghulette)\
**Post date:** [May 12, 2006, 7:55am UTC](https://www.ruby-forum.com/t/globalize-enhancement-zip-code-regexes-for-each-country/60293/2 "2006-05-12T07:55:52Z")

</div>

Depends on what you want.

For example Dutch postal code must adhere to the regular expression  
/^\d\d\d\d [A-Z][A-Z]$/, but it is common to accept “1000aa” (no space,  
lowercase). While the latter is not valid, it can be trivially  
transformed into a valid postal code.

This is not the case for the insane English postal code regular  
expression:  
/^([A-PR-UWYZ]\d\d?\d[ABD-HJLNP-UW-Z]{2}|[A-PR-UWYZ][A-HK-Y]\d\d?\d[ABD-HJLNP-UW-Z]{2}|[A-PR-UWYZ]\d[A-HJKSTUW]\d[ABD-HJLNP-UW-Z]{2}|[A-PR-UWYZ][A-HK-Y]\d[A-HJKRSTUW]\d[ABD-HJLNP-UW-Z]{2}|GIR0AA)$/

You can find more on Wikipedia:

> **[Postal code](https://en.wikipedia.org/wiki/Postal_code)**
>
> A postal code (also known locally in various English-speaking countries throughout the world as a postcode, post code, PIN or ZIP Code) is a series of letters or digits or both, sometimes including spaces or punctuation, included in a postal address for the purpose of sorting mail.
> As of August 2021,\[ref\] the Universal Postal Union lists 160 countries which require the use of a postal code.
> Although postal codes are usually assigned to geographical areas, special codes are sometimes assigned ...

> **[Postcodes in the United Kingdom](https://en.wikipedia.org/wiki/UK_postcodes)**
>
> Postal codes used in the United Kingdom, British Overseas Territories and Crown dependencies are known as postcodes (originally, postal codes). They are alphanumeric and were adopted nationally between 11 October 1959 and 1974, having been devised by the General Post Office (Royal Mail). A full postcode is known as a "postcode unit" and designates an area with several addresses or a single major delivery point.
> The structure of a postcode is two alphanumeric codes that show, first, the Post...

[Postcodereeksen - Wikipedia](http://nl.wikipedia.org/wiki/Postcodereeksen) (Dutch)

Regards,  
Erik.

Geoff H. schreef:
