|
Posted by Toby Inkster on 11/29/06 23:05
nemo wrote:
> Any chance of your divulging the expression to check for the validity
> of format of UK postcodes, please?
I did post the entire source code earlier, but if you'd like an all-in-one
regexp, then you could do a lot worse than...
/([A-PR-UWYZ][A-HK-Y]?([0-9]{1,2}|[1-9][A-HJKMNPR-Y])\s+[0-9][ABDEFGHJLN
P-UW-Z]{2})|(BFPO\s+(c..?o\s+)?([0-9]{1,4}))|(GIR\s+0AA)|(SAN\s+TA1)|((
(ASCN)|(BBND)|(BIQQ)|(FIQQ)|(PCRN)|(SIQQ)|(STHL)|(TDCU)|(TKCA))\s+1ZZ)/
You'll need to remove the line breaks -- this regexp should contain no
white space. Note that this allows any amount of white space between
outgoing and incoming parts of the postcode (e.g. 'AB10 1AB' and
'AB10 1AB' both pass the test. It's a fairly trivial matter to collapse
that down if required.
This is untested, but compiled from several that I do use.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
[Back to original message]
|