note 35058 deleted from function.ereg by kennyt

From: Date: Wed, 26 Jan 2005 03:47:52 +0000
Subject: note 35058 deleted from function.ereg by kennyt
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-83961@lists.php.net to get a copy of this message
Note Submitter: subscriber at gardening-uk dot com ---- 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.

« previous php.notes (#83961) next »