0

I'm trying to validate a UK post code field in MS Access using the LIKE function and I need to be able to allow the possibility that a character be A-Z, 0-9, or simply not be present.

Some postcodes have 1 digit for the first section, others have 2.

So far I have the following:

Like "[A-Z][A-Z,0-9][A-Z,0-9][A-Z,0-9,][ ][0-9][A-Z,0-9][A-Z,0-9]"

However, the third and fourth characters may not even exist in a given post code, how can I handle this?

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
KAT
  • 23
  • 6
  • You need to use a regex not like. If you substitute one of the regexes from [this answer](http://stackoverflow.com/questions/164979/uk-postcode-regex-comprehensive) into the code in PaulFrancis's answer, you will be most of the way there. – John Powell Jan 20 '15 at 18:46

1 Answers1

0

This is a function which I have used in the past, not sure if it is the best. However I know it work(ed)s. So you might want to give it a try.

http://mikeperris.com/access/VBA-code-validate-UK-postcode.html

The Author of the code uses a RegEx patter to match the post code based on its length. This provides a major advantage of avoiding the use of LIKE.

Provides a simple True, if the postcode is valid or False, if it is invalid.

PaulFrancis
  • 5,748
  • 1
  • 19
  • 36