Allowing both UK and US PostCodes
As I am based in the UK, one of the first changes I made to the RailsSpace code (in fact I replaced it as I was going through the particular examples) was to allow for both UK and US postcodes in the User model.
This initial change was essentially very simple, although it resulted in a fairly complex custom regex validation in order to fully validate the various forms of postcodes in use in the uk. The final regex validation in my modified RailsSpace currently looks like this:
validates_format_of :zip_code,
:with => /^$|^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW]) [0-9][ABD-HJLNP-UW-Z]{2}$|^\d{5}$|^\d{5}-\d{4}$)/i,
:message => "must be a valid zip or post code"
This allows for the entering of UK postcodes, but there is still the issue of getting location searches to work world-wide; I'll cover my attempt at this using GeoKit in a future blog post.
Modified about 1 year ago
The code displays funnily in my browser - it stretched for 2 miles on the right of the window. Is this my browser or the RailsSpace needs polishing (I'm asking coz I wouldn't like this to happen on my project)? Cheers! Ty
It's just that RailsSpace needs some polishing. Nothing more than a few css classes however.