note 29391 added to function.ereg

From: Date: Wed, 12 Feb 2003 10:51:37 +0000
Subject: note 29391 added to function.ereg
Groups: php.notes 
Request: Send a blank email to php-notes+get-43816@lists.php.net to get a copy of this message
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; } } -- http://www.php.net/manual/en/function.ereg.php http://master.php.net/manage/user-notes.php?action=edit+29391 http://master.php.net/manage/user-notes.php?action=delete+29391 http://master.php.net/manage/user-notes.php?action=reject+29391

« previous php.notes (#43816) next »