Wes Gamble
2006-Jul-14 20:32 UTC
[Rails] Setting up a Proc for conditional validation (:if option)
I want to use the :if option on one of my validation calls.
Basically I want to validate for a field''s format, but only if the
field
is submitted. It''s an optional field.
validates_format_of :EMAIL, :if => Proc.new { |email| ! email.nil? },
:message => ''is not a valid email
address'',
:with => /^[-\w\.]+@([-\w]+\.)+[-\w]{2,4}$/
Is this correct? It doesn''t seem to be working.
Is it easier to use the method or string forms of :if?
Thanks,
Wes
--
Posted via http://www.ruby-forum.com/.
