# Another validation question

**URL:** <https://www.ruby-forum.com/t/another-validation-question/133569>\
**Category:** Rails\
**Created:** [April 1, 2008, 7:17pm UTC](https://www.ruby-forum.com/t/another-validation-question/133569 "2008-04-01T19:17:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [April 1, 2008, 7:17pm UTC](https://www.ruby-forum.com/t/another-validation-question/133569/1 "2008-04-01T19:17:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [April 1, 2008, 8:28pm UTC](https://www.ruby-forum.com/t/another-validation-question/133569/2 "2008-04-01T20:28:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [April 2, 2008, 2:01am UTC](https://www.ruby-forum.com/t/another-validation-question/133569/3 "2008-04-02T02:01:14Z")

</div>

On Apr 1, 2:27 pm, harm [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 🙂
