?
Solved

Check if Request.Form contains certain values

Posted on 2009-07-14
4
Medium Priority
?
395 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:AVONFRS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
fsouzabrasil earned 2000 total points
ID: 24848701
use IndexOf try:

if (Request.Form["comment"].IndexOf("Dog")>-1){
//Your code is here;
}
0
 
LVL 9

Expert Comment

by:rg20
ID: 24848879
Here is an article with code and modifications below which does close to what your looking for

http://weblogs.asp.net/andrewrea/archive/2008/05/03/bad-word-filter-with-regular-expressions.aspx

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

http://www.codingforums.com/showthread.php?t=9845

<?
set the URL
$url='and+a+if+yaks+are+or+cooler+a+than+llamas';

/*array of no words*/
$no=array('and','a','if','or','a','are');

'removes words which are offensive
function lose_stuff(&$array,$no){
while(list($key,$var)=each($array)){
    if(in_array($var,$no)){
      unset($array[$key]);
      $no_incs[]=$var;
    }
  }
  return $no_incs;
}
reconfigure the URL
$search = explode('+',$url);
$errs=lose_stuff($search,$no);

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 :)
0
 
LVL 1

Author Comment

by:AVONFRS
ID: 24849115
Thanks for your reply fsouzabrasil.

After putting the following in:

                  if(Request.Form["your comment"].IndexOf("Dog")>-1)
                  {
                        sendStatus.Text="testing")
                  }

I get

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

0
 
LVL 4

Expert Comment

by:fsouzabrasil
ID: 25082677
Thanks, can i help you more anything?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question