You have a few options. Here''s one way:
def validate
errors.add :first_name, "can''t be admin" if
self.first_name == "admin"
errors.add :notes, "must not contain more than one URL" if
find_spam(
self.notes)
end
There''s also validates_each.
See the api for this. It sure could be documented better but there are a few
examples.
On 11/24/06, snacktime <snacktime-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
>
> I looked all over last night trying to find the best way to create
> custom validations in an activerecord class. Anyone have a link or
> example lying around? The custom validation can''t be done with a
> regular expression.
>
> Chris
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---