Hi there This might be a stupid question, but I didn''t found anything googling the ''Net. I have created a "stupid" little scaffold to insert data into the db. but i want to validate the data.. This works perfectly: [SNIP] class Phrase < ActiveRecord::Base validates_presence_of :r_or_s, :number, :description validates_numericality_of :number end [/SNIP] but now, I want to check if the r_or_s-field-value is really "r" or "s". so I heard about regular expressions and tried doing that: validates_format_of :r_or_s, :with => ^(r|s)$, :on => :create Why doesn''t that work? Where is a reference who shows me how to use regular expressions??? kindest regards markus -- 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 -~----------~----~----~----~------~----~------~--~---
> validates_format_of :r_or_s, :with => ^(r|s)$, :on => :create > > Why doesn''t that work? Where is a reference who shows me how to use > regular expressions???You could try: validates_format_of :r_or_s, :with => /^(r|s)$/, :on => :create For reference checkout http://www.regular-expressions.info/ or the more in depth O''Reilly book "Mastering Regular Expressions, Powerful Techniques for Perl and Other Tools". -- Company - http://primalgrasp.com Thoughts - http://deezsombor.blogspot.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 -~----------~----~----~----~------~----~------~--~---
Markus Zuercher wrote:> so I heard about regular expressions and tried doing that: > validates_format_of :r_or_s, :with => ^(r|s)$, :on => :createYou can do this without regular expressions validates_inclusion_of :r_or_s, :in => %w( r s ), :on => :create -- 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 -~----------~----~----~----~------~----~------~--~---
On 22/08/06, Markus Zuercher <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> validates_format_of :r_or_s, :with => ^(r|s)$, :on => :createvalidates_format_of :r_or_s :with => /^(r|s)$/, :on => :create -- Cheers, Hasan Diwan <hasan.diwan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---