I found something on the forums and tried it. Now no matter what i enter i get the illegal characters found message. My code is below.
if( !preg_match('/^[A-Za-z0-9]$/',$username) )
{
$page_header;
include('nav.php');
echo "<center><b>Your username contains invalid characters.<br><a href=\"#\" onclick=\"javascript:history.go(-1)\">Back to registration form</a></b></center>";
include('footer.php');
exit();
}