This is the code I wrote to check user's input. Works well except when $key[country] is equal to United Kingdom. Works fine when it's set to United States. Can't understand why so if any of you can, please point it out!
foreach ($HTTP_POST_VARS as $key => $value)
{
if ($key == "username" or $key =="firstname" or $key =="lastname" or $key =="address1" or $key =="address2" or $key =="county" or $key =="postcode" or $key =="country")
{
if (!preg_match("/^[A-Za-z'0-9 -]{1,40}$/", $value))
{
$bad_format[$key] ="bad";
}
}
}