laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Feb-01 20:02 UTC
How do I allow an empty value in my model?
Hi, If a user enters a value for the field "work_phone", I want to validate it against a reg-exp. However, if the field is completely blank, I''d like to allow that too. This doesn''t work, though validates_format_of :work_phone, :with => %r{^(\+\d)*\s*(\(\d{3}\) \s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$}, :allow_empty => true What is the right way to validate the field in the model? - Dave --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org wrote:> Hi, > > If a user enters a value for the field "work_phone", I want to > validate it against a reg-exp. However, if the field is completely > blank, I''d like to allow that too. This doesn''t work, though > > validates_format_of :work_phone, :with => %r{^(\+\d)*\s*(\(\d{3}\) > \s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$}, :allow_empty > => true > > > What is the right way to validate the field in the model? - Daveif you are on 2.0.2 then you can use :allow_blank => true -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I believe it''s allow_nil => true. Peace, Phillip On Feb 1, 2008, at 2:02 PM, laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org wrote:> > Hi, > > If a user enters a value for the field "work_phone", I want to > validate it against a reg-exp. However, if the field is completely > blank, I''d like to allow that too. This doesn''t work, though > > validates_format_of :work_phone, :with => %r{^(\+\d)*\s*(\(\d{3}\) > \s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$}, :allow_empty > => true > > > What is the right way to validate the field in the model? - Dave > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Feb-01 21:05 UTC
Re: How do I allow an empty value in my model?
allow_blank is the answer. 5 stars. - On Feb 1, 2:24 pm, "Vapor .." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org wrote: > > Hi, > > > If a user enters a value for the field "work_phone", I want to > > validate it against a reg-exp. However, if the field is completely > > blank, I''d like to allow that too. This doesn''t work, though > > > validates_format_of :work_phone, :with => %r{^(\+\d)*\s*(\(\d{3}\) > > \s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$}, :allow_empty > > => true > > > What is the right way to validate the field in the model? - Dave > > if you are on 2.0.2 then you can use :allow_blank => true > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---