cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

UK postcode Rule

Former Member
0 Likes
1,894

Hi All,

I tried to write a a rule for UK postcode validation by using Match Pattern .when I test it giving right answers.

but this match pattern passing just first half postcode (AA9)  also pass.

when I bind it to the postcode column it passing all the patterns except Just Numbers(12345,123456,7896-----fail) in that field.

it gives score 9.99.

Did anyone came across this problem,

please help me out or please can anyone share if they wrote the rule for this already.

Regards

Kumarr

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member655569
Participant
0 Likes

Try this...

BEGIN

IF(

( match_pattern($Name, 'X9 9XX')) OR

( match_pattern($Name, 'X99 9XX')) OR

( match_pattern($Name, 'XX9 9XX')) OR

.............

)

Return True;

Else

Return False;

END

System takes any characters in place of X and any number in place of 9.

Former Member
0 Likes

Hi Adrian Thanks for the good suggestion with example.I tried the same with regular expression.

showing sample

(match_regex($POSTCODE, '[A-Z][0-9]{2} [0-9]{1}[A-Z]{2}', NULL)

match_regex($POSTCODE, '[A-Z]{2}[0-9] [0-9]{1}[A-Z]{2}', NULL)

match_regex($POSTCODE, '[A-Z][0-9][A-Z] [0-9]{1}[A-Z]{2}', NULL))

And  Thanks for the link also.

Former Member
0 Likes

Kumarr,

I'm not sure what the acceptable formats of a UK post code are.  However, you may want to look at the REGEX rather than match pattern rule.  With that you can specify numbers and if appropriate letters of allowable characters and length of the post code.

regards

Adrian

Former Member
0 Likes

Hi Adrian Storen,

Thanks for a response.

Here is the UK standard postcode patterns

X9 9XX 

X99 9XX

XX9 9XX

XX99 9XX

X9X 9XX  

XX9X 9XX.

i tried using Match pattern ,I tried with reg exp also but results are coming in same way.

Thanks

Kumarrr

Former Member
0 Likes

Assume by '9' you mean any number rather than always a 9.  Did you try multiple regex statements with OR statements?

match_regex($post_code, '[A-Z]{1}[0-9]{1}\s[0-9]{1}[A-Z]{2}', NULL) OR

match_regex($post_code, '[A-Z]{1}[0-9]{2}\s[0-9]{1}[A-Z]{2}', NULL) OR

match_regex($post_code, '[A-Z]{2}[0-9]{1}\s[0-9]{1}[A-Z]{2}', NULL) OR ... etc

Former Member
0 Likes

Or look here:

http://stackoverflow.com/questions/164979/uk-postcode-regex-comprehensive

This has a reference to the UK Government Standard.