# Check UK postcode format # Format is LD DLL, LLD DLL, LDD DLL, or LLDD DLL where L = letter, D = digit $postcode = uc($postcode); # Could be removed if you use the /i regex switch if ($postcode !~ /^(([A-Z]\d|[A-Z][A-Z]\d|[A-Z]\d\d|[A-Z][A-Z]\d\d)\s(\d|o)[A-Z][A-Z])$/i) { $error_msg .= "Invalid postcode for UK.

\n"; }