if(preg_match('/[-a-z0-9!@# ]+$/i', $GET['thevalue'])){
//it's OK
}else{
//sorry, illegal characters
}
I suggest you also convert combinations like <? and ?> and <% and %> into their ascii code equivalents. For example < is ascii 060 and ? is ascii 063, so change <? over to <? when you store it.
That way they can't pass scripts -- <? will still display as <?
Sam