/ Published in: ASP
URL: http://reusablecode.blogspot.com/2008/08/isvalidpostcode.html
Expand |
Embed | Plain Text
<% ' 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) dim regEx set regEx = new RegExp with regEx .IgnoreCase = true .Global = true .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))$" end with if regEx.Test(trim(CStr(postCode))) then isValidPostCode = true else isValidPostCode = false end if set regEx = nothing end function %>
You need to login to post a comment.
