Should it start with one of those two-letter combinations? Then use:
if (in_array(substr($_GET['postcode'], 0, 2), $validatepostcode) {
// redirect
}
If you have multiple length prefixes you can use:
for ($i = $min_prefix_length; $i <= $max_prefix_length; $i++) {
if (in_array(substr($_GET['postcode'], 0, $i), $validatepostcode) {
// redirect
}
}
Or (more efficient):
$valid_prefixes = array(
2 => array('NH', 'AQ'),
3 => array('NZ2', 'GT5'),
);
foreach($valid_prefixes as $length => $prefixes) {
if (in_array(substr($_GET['postcode'], 0, $length), $prefixes) {
// redirect
}
}
You can use regular expressions like ^(NH|AQ|NZ2|GT5)
but I don't think that would be a good solution if you have a lot of options.