PostCode validation for UK in a Microflow (exclusive split)

0
Hi all, I am wondering whether someone can help me with the expression I can use for post code validation for patient in UK in my microflow, in an exclusive split. In the exclusive split I have used the below which seemed to work: $Patient/Postcode = empty or $Patient/Postcode = '' So, if the above is "true" then I show an error message, if False, I accept the value user has entered. But when I used the below I get an error and it does not validate the post code properly: isMatch ($Patient/Postcode,'^[0-9]+)$£!&*()') I am not sure whether I am using this correctly, as what I intend to do is, to validate a correct post code but display an error message when have characters such as ",!,£,$,%,^,&,*,(,) {,},<,>,?,\ Can someone please help me to resolve this please? This is on Mendix version 5.9.1 Thanks Nimesh
asked
4 answers
1

Take a look at this post at stackoverflow: http://stackoverflow.com/questions/164979/uk-postcode-regex-comprehensive It provides the official regex of the UK government. If you have problems checking this regex let us now so we can help you further.

Regards,

Ronald

[EDIT] Look here for the documentation here: https://world.mendix.com/display/refguide6/Regular+Expressions and the part about java here: http://www.regular-expressions.info/java.html You should excape the characters with a extra slash \.

answered
0

Okay, thanks for the link, just to confirm, am I using IsMatch correctly with the below?

isMatch ($Patient/Postcode,'^(([gG][iI][rR] {0,}0[aA]{2})|((([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y]?[0-9][0-9]?)|(([a-pr-uwyzA-PR-UWYZ][0-9][a-hjkstuwA-HJKSTUW])|([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y][0-9][abehmnprv-yABEHMNPRV-Y]))) {0,}[0-9][abd-hjlnp-uw-zABD-HJLNP-UW-Z]{2}))$')

or should it be different to reject the characters such as such as ",!,£,$,%,^,&,*,(,) {,},<,>,?,\ ?

When I used the above, it seem to be accepting all the nonsensical characters, and I have also tried similar to below: isMatch($yourvariable, '^([0-9]+)$') it has not worked.

answered
0

Hi all,

I have validated the below regular expression for UK post codes in Regular Expression testing sites, but when I use the same with isMatch, I get an error and the post code for e.g: OX1 1LF, does not seem to get accepted.

I am don't really know what I am not doing correctly here and would really appreciate your help.

Below is my regular expression with the isMatch for your reference:

isMatch ($Patient/Postcode,'[^a-zA-Z]{3}+[^0-9]{3,2}[ ^0-9]+[^a-zA-Z]{2,3}\$')

Please can someone help me? I need urgent help.

Best Regards Nimesh

answered
0

Whatever you do, make sure you create a dedicated microflow for this, so you can call this everytime you validate a postcode, and do not end up having multiple copies of the regex scattered around your application.

We use the following:

isMatch($Postcode,'(GIR ?0AA)|((([A-Z-[QVX]][0-9][0-9]?)|(([A-Z-[QVX]][A-Z-[IJZ]][0-9][0-9]?)|(([A-Z-[QVX]][0-9][A-HJKSTUW])|([A-Z-[QVX]][A-Z-[IJZ]][0-9][ABEHMNPRVWXY])))) ?[0-9][A-Z-[CIKMOV]]{2})')

This looks a lot like the official UK government regex (I didn't even know there was such a thing), and works fine for us so far.

I would not worry too much about allowing whatever characters users will try to put in. In cases like this, you will never get it perfect anyway, and it is better to err on the side of allowing too much then allowing too little.

answered