Geoff Hopson
2006-May-11 20:04 UTC
[Rails] [Globalize] Enhancement - zip code regexes for each country
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060511/48e66412/attachment.html
Erik van Oosten
2006-May-12 05:54 UTC
[Rails] [Globalize] Enhancement - zip code regexes for each country
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 Hopson schreef:> 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
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
Reasonably Related Threads
- validations without AR - going crazy trying to find link
- Nasty pitfall: don''t use ^ and $ in validation regexes!
- if/else regexes?
- Bug#552222: logcheck: dhclient regexes need updating
- Bug#617232: logcheck: ignore regexes match ipv4 addresses only, causing false positives with ipv6 addresses.