"Scott" <sjs...@btinternet.com> wrote in message news:VLx_d.1379$MO6...@newsfe2-gui.ntli.net...
"Bob Phillips" <bob.ph...@notheretiscali.co.uk> wrote in message news:OrJgl%236KF...@TK2MSFTNGP12.phx.gbl...
Bob, Sorry, I didn't know this was a programming question...
Scott, The rules are even more complex than you stated <g>.
Considered setting a reference to Microsoft VBScript Regular
Expressions 5.5 and using a more capable regular expression (the one
from my original post was intended for use in a SQL Server/Jet CHECK
constraint, which support only simple pattern matching, and does not do
the job anyhow). As with all things standardised, the 'not invented
here' mentality should be resisted. Here's somewhere to start looking:
http://regexlib.com/Search.aspx?k=uk%20postcode
Jamie.
--
Point taken though...
Scott
"Jamie Collins" <jamiec...@xsmail.com> wrote in message
news:1111152242....@f14g2000cwb.googlegroups.com...
Did you take a look at the link to regexlib? There seem to be a range
of extremes catered for, from
^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}$
to
^((([A-PR-UWYZ])([0-9][0-9A-HJKS-UW]?))|(([A-PR-UWYZ][A-HK-Y
])([0-9][0-9ABEHMNPRV-Y]?))\s{0,2}(([0-9])([ABD-HJLNP-UW-Z])
([ABD-HJLNP-UW-Z])))|(((GI)(R))\s{0,2}((0)(A)(A)))$
I'd hesitate to endorse one myself, though. Pick one that looks good
enough and do some testing.
BTW your client may have some input to this e.g. I've seen an Inland
Revenue regex for postcode that was fairly simple and if it'd good
enough for them...
Jamie.
--
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Scott" <sjs...@btinternet.com> wrote in message
news:vKA_d.486$yW1...@newsfe4-gui.ntli.net...
If the code is correct input, there are only 2 patterns to match in the
code that I gave
[A-Z][A-Z]## #[A-Z][A-Z]
[A-Z]## #[A-Z][A-Z]
so the saving on RegEx is minimal. All of the other patterns I gave are for
your particular format/output requirements.
I also tried some of the patterns provided in the link that Jamie gave, and
none was totally accurate in your definition of a valid postcode. I am sure
that they can be adapted to be 'perfect', but I don't feel confident enough
with patterns as of yet.
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Bob Phillips" <bob.ph...@notheretiscali.co.uk> wrote in message
news:%23uuP8V8...@TK2MSFTNGP12.phx.gbl...