So after searching the internet for a considerable amount of time to try to find the right way to validate UK postcodes to a fairly accurate dataset I have come up with the following solution. For reference the field containing my postcode is called Postcode.
Using the formatting conditions input the following:
| Field |
Match Type |
Condition |
| Postcode |
does not match pattern |
[A-PR-UWYZ][A-HK-Y]?[0-9]{1,2} ?[0-9][ABD-HJLNP-UW-Z]{2} |
| Postcode |
does not match pattern |
[A-PR-UWYZ][0-9][A-HJKSTUW] ?[0-9][ABD-HJLNP-UW-Z]{2} |
| Postcode |
does not match pattern |
[A-PR-UWYZ][A-HK-Y][0-9][CDFGI-LOQSTUZ] ?[0-9][ABD-HJLNP-UW-Z]{2} |
| Postcode |
is equal to |
GIR 0AA |
All these should end with an "and". Use custom pattern to insert the conditions for pattern matching.
There are a lot of RegEx examples out there, however InfoPath doesn't fully support it. If anyone has a better solution than this I would be interested to hear it, as this isn't the most elegant of solutions.