hi,
i''m trying to validate the format of a date and have the following
regular code:
validates_presence_of :dob
validates_format_of :dob,
:with => /^[0-9]{4}[-][0-9]{2}[-][0-9]{2}$/,
:unless => Proc.new { |u| u.dob.blank? }
i''ve checked the regexp independently and it works, and i''ve
put this
regexp with telephone, and it checks the dates correctly (telephone is a
integer type), however when i do it with dob it''ll give me some strange
results:
23-12-2008 will be valid, while 23-13-2008 won''t. so i''m
guessing it''s
checking whether dates are valid completely independently from my
validations, however this isn''t what i want.
am i missing something here?
thanks
daniel
--
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
-~----------~----~----~----~------~----~------~--~---
the error message i get if i write 23-13-2008 is "dob can''t be blank" Daniel Fac wrote:> hi, > i''m trying to validate the format of a date and have the following > regular code: > > validates_presence_of :dob > validates_format_of :dob, > :with => /^[0-9]{4}[-][0-9]{2}[-][0-9]{2}$/, > :unless => Proc.new { |u| u.dob.blank? } > > i''ve checked the regexp independently and it works, and i''ve put this > regexp with telephone, and it checks the dates correctly (telephone is a > integer type), however when i do it with dob it''ll give me some strange >-- 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 -~----------~----~----~----~------~----~------~--~---
On Oct 11, 1:41 am, Daniel Fac <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> the error message i get if i write 23-13-2008 is "dob can''t be blank" >At the point the validation runs the string ''23-13-2008'' has been turned into an actual date (ie an instance of Time or Date depending on your column type), so validating its format is nonsensical. Fred> Daniel Fac wrote: > > hi, > > i''m trying to validate the format of a date and have the following > > regular code: > > > validates_presence_of :dob > > validates_format_of :dob, > > :with => /^[0-9]{4}[-][0-9]{2}[-][0-9]{2}$/, > > :unless => Proc.new { |u| u.dob.blank? } > > > i''ve checked the regexp independently and it works, and i''ve put this > > regexp with telephone, and it checks the dates correctly (telephone is a > > integer type), however when i do it with dob it''ll give me some strange > > -- > 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 -~----------~----~----~----~------~----~------~--~---