validate email format only if not blank Rails 3

Viewed 37249

I want to validate the email only if the email has been entered.

I tried the following:

validates :email, :presence => {:message => "Your email is used to save your greeting."},
                  :email => true,
                  :if => Proc.new {|c| not c.email.blank?},
                  :uniqueness => { :case_sensitive => false }

However this does not work as it stops error messages from showing when the email is left blank.

How can I validate the presence of the email when it is missing and ONLY validate the format when it has been entered?

3 Answers
Related