If you only need upper-case, simply convert it:

Conceptually:
Code:
$postcode = strtoupper($postcode);

If you want to manually insert the space as the 5th character, you could manipulate it like this:

Code:
$postcode = str_replace(array(' ', '-'), '', $postcode);
$postcode = substr($postcode, 0,4,) . ' ' . substr($postcode, 5);
If you're trying to validate the order of letters and numbers etc, you'd need to write more advanced code...