Preventing users from using your app name in their name

Is there a Rails validation helper or an easy way of preventing attributes from containing a certain word match, e.g. you have a User model, the user has a name attribute, and you don't want the @user.name to == 'MyRailsApp' or to have 'MyRailsApp' somewhere in there?

I imagine it would look something like this (although I can't get this one to work - it always fails);

  validates_format_of :name, :with => /!MyRailsApp/i, :message => "You can't use our Website name."

Any ideas?

Try this one:

validates_each :name do |record, attr, value|   record.errors.add attr, "can't use our Website name." if value =~ / MyRailsApp/i end

Neil Cauldwell wrote:

Any ideas?

Try validates_exclusion_of

http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=M001745&name=validates_exclusion_of

Peace.

Erol Fornoles wrote: