I have tried the one on the .gov website, as stated on many questions here, but it doesnt seem to work for short postcodes.
My regex:
preg_match('^(([gG][iI][rR] {0,}0[aA]{2})|((([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y]?[0-9][0-9]?)|(([a-pr-uwyzA-PR-UWYZ][0-9][a-hjkstuwA-HJKSTUW])|([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y][0-9][abehmnprv-yABEHMNPRV-Y]))) {0,}[0-9][abd-hjlnp-uw-zABD-HJLNP-UW-Z]{2}))^', $this->post['location'], $matches)
When I use a long postcode of format: AA9 9ZZ
it works, but one of format AA9
doesnt. I need the following formats to work:
- AA9
- AA99
- AA9 9ZZ
- AA99 9ZZ