Page 1 of 1

Matching a UK Postcode

Posted: Sat Jul 02, 2011 1:23 pm
by construct
Useful regex to match a valid UK Postcode.

Code: Select all

$postal = 'AL42PT';
 
if(preg_match("/^[A-Z]{1,2}([0-9]{1,2}|[0-9]{1,1}[A-Z]{1,1})( |)[0-9]{1,1}[A-Z]{2,2}$/", $postal)) {
 
  echo $postal;
 
}
Source: TutorialCadet

Re: Matching a UK Postcode

Posted: Sat Jul 02, 2011 5:21 pm
by McInfo