So, based on the what all (particularly Fred) have said...

1) The easiest fix is to treat the zip code and plus4 as strings.
After all, do you plan on using them as arithmetic values?  This has
the unfortunate byproduct of allowing "00000" "0000" as valid fields.

2) If you do continue with the fields as integers, you could validate
with:

validate_numericality_of :zip_code :only_integer => true,
   :greater_than_or_equal_to 00000,
   :less_than_or_equal_to 99999

Both cases have the unfortunate result of allowing non-zips and non-
plus4s (in terms of USPS rules) into your database.  I think you would
be better off to extend your model to acquire the street address from
the user and ask USPS for the valid zip and plus4.

See: http://zip4.usps.com/zip4/welcome.jsp


On Nov 16, 7:07 am, "Todd A. Jacobs" <tjacobs-sndr-
b4f...@codegnome.org> wrote:
> On Mon, Nov 16, 2009 at 11:38:14AM +0000, Colin Law wrote:
> > Is it a string or numeric field in the db?
>
> It's an integer.
>
> --
> "Oh, look: rocks!"
>         -- Doctor Who, "Destiny of the Daleks"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to