Check if Request.Form contains certain values

I am trying to edit a webpage we have in C#, which receives data from a form.

I want to be able to see if the text contains certain words. We are using it to block people from sending explicit emails on our website contact form.

I currently have this and that is it, i dont know what to put after it that searches for words. Lets just say those words i want to search for are Dog, Cat & Rabbit (if i used the actual words most peoples proxy servers would block this topic).

if (Request.Form["comment"] ----- and then i want it to say look for Dog, Cat & Rabbit. If true, then do something.
Who is Participating?
fsouzabrasilConnect With a Mentor Commented:
use IndexOf try:

if (Request.Form["comment"].IndexOf("Dog")>-1){
//Your code is here;
Here is an article with code and modifications below which does close to what your looking for

if you want to keep it simpler,  you can create an array of words you want to filter, then parse the string for those words

even though this is written in PHP you can use the logic

set the URL

/*array of no words*/

'removes words which are offensive
function lose_stuff(&$array,$no){
  return $no_incs;
reconfigure the URL
$search = explode('+',$url);

echo 'Sorry but the words '.implode(',',$errs).' were not included';
echo '<br />searching for ... '.implode(',',$search);

Another effective meathod is to have one of those enter this code pictures on the page, it will stop bots, for now :)
AVONFRSAuthor Commented:
Thanks for your reply fsouzabrasil.

After putting the following in:

                  if(Request.Form["your comment"].IndexOf("Dog")>-1)

I get

System.NullReferenceException: Object reference not set to an instance of an object.

Thanks, can i help you more anything?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.