I am trying to do a very basic zipcode validation(zip is a int field in mysql). validates_presence_of :zip, :message => "Can''t be blank" validates_format_of :zip, :with => /^[0-9]{5}(-[0-9]{4})?$/, :message => "Invalid Zipcode" No matter whatever valid 5 digit zip I enter, this does not work, but If I do a ''12345''.match (/^[0-9]{5}(-[0-9]{4})?$/) it works just fine! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
It seems both validations fail, the message says "Can''t be blank and shold be 5 digits", when its actually both. On Jul 25, 5:17 pm, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am trying to do a very basic zipcode validation(zip is a int field > in mysql). > > validates_presence_of :zip, :message => "Can''t be blank" > validates_format_of :zip, :with => /^[0-9]{5}(-[0-9]{4})?$/, :message > => "Invalid Zipcode" > > No matter whatever valid 5 digit zip I enter, this does not work, but > If I do a > ''12345''.match (/^[0-9]{5}(-[0-9]{4})?$/) it works just fine!-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, Jul 25, 2010 at 5:17 PM, badnaam <asitkmishra-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am trying to do a very basic zipcode validation** (zip is a int field in mysql) **> validates_format_of :zip, :with => /^[0-9]{5}(-[0-9]{4})?$/Uh, you''re trying to use a regular expression on an int? Off the top of my head that seems unlikely to work...> No matter whatever valid 5 digit zip I enter, this does not work, but > If I do a > ''12345''.match (/^[0-9]{5}(-[0-9]{4})?$/) it works just fine!.. as the above would seem to confirm. HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks, I did change the field to varchar(5) as well, that doesn''t work eitehr On Jul 25, 5:32 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Jul 25, 2010 at 5:17 PM, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I am trying to do a very basic zipcode validation > > ** (zip is a int field in mysql) ** > > > validates_format_of :zip, :with => /^[0-9]{5}(-[0-9]{4})?$/ > > Uh, you''re trying to use a regular expression on an int? Off the top > of my head that seems unlikely to work... > > > No matter whatever valid 5 digit zip I enter, this does not work, but > > If I do a > > ''12345''.match (/^[0-9]{5}(-[0-9]{4})?$/) it works just fine! > > .. as the above would seem to confirm. > > HTH, > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassan-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Nevermind, I did not put zip in attr_accessible, that''s why it was failing. Doh!! On Jul 25, 5:49 pm, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks, I did change the field to varchar(5) as well, that doesn''t > work eitehr > > On Jul 25, 5:32 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Sun, Jul 25, 2010 at 5:17 PM, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I am trying to do a very basic zipcode validation > > > ** (zip is a int field in mysql) ** > > > > validates_format_of :zip, :with => /^[0-9]{5}(-[0-9]{4})?$/ > > > Uh, you''re trying to use a regular expression on an int? Off the top > > of my head that seems unlikely to work... > > > > No matter whatever valid 5 digit zip I enter, this does not work, but > > > If I do a > > > ''12345''.match (/^[0-9]{5}(-[0-9]{4})?$/) it works just fine! > > > .. as the above would seem to confirm. > > > HTH, > > -- > > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > twitter: @hassan > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.