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

On Apr 1, 2:27 pm, harm [email protected] wrote:

That would be easy I think.
Just create a blacklist and match against that.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs