Forum: Ruby on Rails [Globalize] Enhancement - zip code regexes for each country

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Geoff H. (Guest)
on 2006-05-12 00:06
(Received via mailing list)
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
Erik van Oosten (Guest)
on 2006-05-12 09:55
(Received via mailing list)
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:
http://en.wikipedia.org/wiki/Postal_code
http://en.wikipedia.org/wiki/UK_postcodes
http://nl.wikipedia.org/wiki/Postcodereeksen (Dutch)

Regards,
     Erik.



Geoff H. schreef:
This topic is locked and can not be replied to.