The example above is still a great one. However, to make sure you wish to remain between a-z and 0-9 characters, you could always replace the above with this one:
PHP Code:
foreach ($_POST as $key => $val) {
if (preg_match("/[a-z0-9\-\_\s]/i", $val)) {
if (is_array($val)) {
foreach($val as $sub_key => $sub_val) {
$_POST[$key][$sub_key] = htmlentities($sub_val, ENT_QUOTES);
}
} else {
$_POST[$key] = htmlentities($val, ENT_QUOTES);
}
} else {
$messageStack->add('your_page_name_here', YOUR_TEXT_DEFINITION_NAME_HERE');
}