I have the following validation code, however it will allow variations in case. Like ''Admin'' and ''admiN'', etc validates_exclusion_of :login, :in => %w( admin ), :message => "is reserved for system accounts" how can I make this validation case insensitive? -- Posted via http://www.ruby-forum.com/.
Jonathon Marshall wrote:> I have the following validation code, however it will allow variations > in case. Like ''Admin'' and ''admiN'', etc > > validates_exclusion_of :login, :in => %w( admin ), > :message => "is reserved for system accounts" > > how can I make this validation case insensitive?This works validates_format_of :login, :with => /^[^admin|administrator|root|sysadmin|superuser|moderator|support|god]$/i, :message => "is reserved for system accounts" -- Posted via http://www.ruby-forum.com/.
Jonathon Marshall wrote:> Jonathon Marshall wrote: >> I have the following validation code, however it will allow variations >> in case. Like ''Admin'' and ''admiN'', etc >> >> validates_exclusion_of :login, :in => %w( admin ), >> :message => "is reserved for system accounts" >> >> how can I make this validation case insensitive? > > This works > > validates_format_of :login, :with => > /^[^admin|administrator|root|sysadmin|superuser|moderator|support|god]$/i, > :message => "is reserved for system accounts"sorry that does not work and I did not mean to post it. -- Posted via http://www.ruby-forum.com/.
On 14/08/06, Jonathon Marshall <jwm@1101001.com> wrote:> > >> how can I make this validation case insensitive? >Technically, it doesn''t solve the problem, rather the code avoids it in the first instance. users = %w( admin Admin admiN ).each(|element| element.downcase! } validates_exclusion_of :login, :in => users, :message => ''is reserved for system accounts'' -- Cheers, Hasan Diwan <hasan.diwan@gmail.com> -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060815/de6d6b54/attachment.html