AVONFRS
asked on
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your reply fsouzabrasil.
After putting the following in:
if(Request.Form["your comment"].IndexOf("Dog")>- 1)
{
sendStatus.Text="testing")
}
I get
System.NullReferenceExcept ion: Object reference not set to an instance of an object.
After putting the following in:
if(Request.Form["your comment"].IndexOf("Dog")>-
{
sendStatus.Text="testing")
}
I get
System.NullReferenceExcept
Thanks, can i help you more anything?
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
/*array of no words*/
$no=array('and','a','if','
'removes words which are offensive
function lose_stuff(&$array,$no){
while(list($key,$var)=each
if(in_array($var,$no)){
unset($array[$key]);
$no_incs[]=$var;
}
}
return $no_incs;
}
reconfigure the URL
$search = explode('+',$url);
$errs=lose_stuff($search,$
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 :)