note 29391 deleted from function.ereg by kennyt

From: Date: Wed, 26 Jan 2005 03:49:11 +0000
Subject: note 29391 deleted from function.ereg by kennyt
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-83969@lists.php.net to get a copy of this message
Note Submitter: gunter dot creasey at amenz dot net ---- Concerning UK Postcodes: There are 6 standard prefix patterns for each postcode. Prefixes are 1A1N 1A2N 2A1N 2A2N 1A1N1A 2A1N1A To my knowledge all combinations of letters and numbers are potentially valid for the prefix. The suffix is standard as 1N2A, but never contains the letters C I K M O V due to the possible confusion with other letters & numbers. Accordingly my function to validate & return a formatted UK postcode is as follows: function VUKPostcode($postcode) { $postcode = strtoupper(str_replace(chr(32),'',$postcode)); $suffix = substr($postcode,-3,3); $prefix = substr($postcode,0,(strlen($postcode)-3)); if (preg_match('/(^[A-Z]{1,2}[0-9]{1,2}|^[A-Z]{1,2}[0-9] {1}[A-Z]{1})$/',$prefix) && preg_match('/^[0-9]{1}[ABD-HJLNP-UW-Z]{2} $/',$suffix)) { return $prefix . chr(32) . $suffix; } else { return FALSE; } }

« previous php.notes (#83969) next »