note 67266 added to function.ereg

From: Date: Tue, 06 Jun 2006 15:41:16 +0000
Subject: note 67266 added to function.ereg
Groups: php.notes 
Request: Send a blank email to php-notes+get-113364@lists.php.net to get a copy of this message
I could not find a definitive and 100% working function that validates the UK postcodes, so was forced to write one myself. The authoritative source of information is http://www.govtalk.gov.uk/gdsc/html/frames/PostCode.htm which I amended with the new postcode for Tristan da Cunha. Here is the ugly beast (don't wanna see regexp's ever again): <?php function IsPostcode($postcode) { $postcode = strtoupper(str_replace(chr(32),'',$postcode)); if(ereg("^(GIR0AA)|(TDCU1ZZ)|((([A-PR-UWYZ][0-9][0-9]?)|" ."(([A-PR-UWYZ][A-HK-Y]][0-9][0-9]?)|" ."(([A-PR-UWYZ][0-9][A-HJKSTUW])|" ."([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))))" ."[0-9][ABD-HJLNP-UW-Z]{2})$", $postcode)) return $postcode; else return FALSE; } ?> ---- Server IP: 85.116.0.130 Probable Submitter: 84.12.157.2 ---- X-Spam-Status: No, hits=3.8 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, UPPERCASE_25_50 autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.ereg.php Edit -- http://master.php.net/note/edit/67266 Del: integrated -- http://master.php.net/note/delete/67266/integrated Del: useless -- http://master.php.net/note/delete/67266/useless Del: bad code -- http://master.php.net/note/delete/67266/bad+code Del: spam -- http://master.php.net/note/delete/67266/spam Del: non-english -- http://master.php.net/note/delete/67266/non-english Del: in docs -- http://master.php.net/note/delete/67266/in+docs Del: other reasons-- http://master.php.net/note/delete/67266 Reject -- http://master.php.net/note/reject/67266 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#113364) next »