Code: PHP
$string = "Asdsd - sdsd ";
 if(!preg_match("/^[A-Za-z0-9-._]+$/",$string)) //see here I allowed -,_ and .
 {
    print("Bad characters found!");
 }