Another validation question

Hi. Are there any validation methods which can prevent users from entering certain words in a field (eg swearing etc) Thanks

That would be easy I think. Just create a blacklist and match against that. If you find a match add some error to the object. Something along these lines:

before_save :catch_swears BLACKLIST = %(some bad words)

private def catch_swears errors.add("Dont swear plz") if BLACKLIST.any?(|swear_word| self.text_field =~ swear_word) end

yeah, easy if the old pharts use proper spelling & grammar :slight_smile: