I'm not sure exactly which the invalid characters are...? 
Maybe it's simply better to return a message to the user and let them enter a valid keyword?