How can a validation exclude a regexp?
I'm looking for something like this:
validates_format_of :string, :without => /\A(something)\Z/
which is mentioned here, but I don't think is a real thing (Unknown validator: 'WithoutValidator
).
:without
option has been there since August of 2009. Are you calling validates_format_of
exactly like in your example - sluukkonen 2012-04-05 22:30
validates :format =>
. I thought they were equivalent and perhaps the validates* methods deprecated, as the official guide doesn't mention them? http://guides.rubyonrails.org/activerecordvalidationscallbacks.htm - mahemoff 2012-04-05 23:10
You could write your own:
validate :name_exclude_pattern
def name_exclude_pattern
unless self.name !~ /\A(something)\Z/
errors.add(:name, "invalid format.")
end
end
Though of course, this would have to be done for each attribute you want to check.