You have to use Regular Expressions (regex) to filter out bad characters.Checkout the exmaple below.

Code: PHP
$string = "Asdsd - sdsd ";
if(!preg_match("/^[\w]+$/",$string))
{
   print("Bad characters found!");
}