/ Published in: PHP
URL: http://reusablecode.blogspot.com/2008/08/isvalidpostcode.html
Expand |
Embed | Plain Text
<?php /* Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved. This work is licensed under the Creative Commons Attribution License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. */ // Checks the validity of the format of a supplied UK postcode. // Completely accurate validation is only possible by attempting to deliver mail to the address, and verifying with the recipient. // Supports all six common postcode formats, Girobank, Father Christmas, British Forces Post Office, and overseas territories. function isValidPostCode($postCode) { $pattern = "/^([A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\ [0-9][ABD-HJLNP-UW-Z]{2}|(GIR\ 0AA)|(SAN\ TA1)|(BFPO\ (C\/O\ )?[0-9]{1,4})|((ASCN|BBND|[BFS]IQQ|PCRN|STHL|TDCU|TKCA)\ 1ZZ))$/i"; } ?>
You need to login to post a comment.
