note 35058 added to function.ereg

From: Date: Mon, 18 Aug 2003 07:00:23 +0000
Subject: note 35058 added to function.ereg
Groups: php.notes 
Request: Send a blank email to php-notes+get-54559@lists.php.net to get a copy of this message
OK. My Take on British Postcodes. I had a sample of nearly 90,000 to check and the following worked best. It handles CR0 0JP and BFPO 10 (British Forces Posted Overseas) which the others posted here didn't. The cleanupPostcode function corrects some common errors prior to validation. function cleanupPostcode ($postcode) { $postcode = strtoupper($postcode); $postcode = ereg_replace('[[:punct:]]', ' ', $postcode); $postcode = ereg_replace('[[:space:]]+', ' ', $postcode); $postcode = str_replace(' O',' 0', $postcode); if ($postcode{0} == '0') $postcode{0} = 'O'; return $postcode; } $postcode = cleanupPostcode($postcode); $valid = eregi('^(([A-Z][A-Z]?)([1-9]*[0-9A-HJ-RT-Y]?))|(BFPO) ?(([0-9]{1}[ABD-HJLNP-UW-Z]{1,2})|([0-9]{2}))$', $postcode); This resulted in "fixing" over 600 carelessly entered postcodes prior to validation. Only safe fixes are performed. ---- Manual Page -- http://www.php.net/manual/en/function.ereg.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35058 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35058&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35058&report=yes

« previous php.notes (#54559) next »