# Postcode validation

**URL:** https://forum.cloverdx.com/t/postcode-validation/2156
**Category:** CloverDX Platform
**Created:** [February 29, 2024, 6:54pm UTC](https://forum.cloverdx.com/t/postcode-validation/2156 "2024-02-29T18:54:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Anouk\_Cederboom](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Anouk\_Cederboom](https://forum.cloverdx.com/u/Anouk_Cederboom)
#### Post date: [February 29, 2024, 6:54pm UTC](https://forum.cloverdx.com/t/postcode-validation/2156/1 "2024-02-29T18:54:31Z")

</div>

Hi,  
I have a list of customers for which I’d like to check if the postcodes are valid based on a regular expression. The only thing is that my list of customers contains customers from all over Europe.

I started of by using the validator component to validate the pattern of the postcode with a regular expression as a pattern. Initialy I used the IF-THEN-ELSE part in which the IF part consits of an expression where I’m checking if the country field (string field) equals a specific value like “NL” this way I can filter on a specific value and then in the THEN part I added the regular expression of the common postcode for NL. However, the IF part doesn’t filter on only the country value NL, but instead selects all the values for countries in the field $in.0.COUNTRY and then checks on the pattern in the then part.

I’ve also tried to use only a expression rule and in that rule use the function iif( $in.0.COUNTRY == “NL” AND $in.0.POSTCODE == “^[1-9][0-9]{3} ?[A-Z]{2}\s\*”, TRUE, FALSE), but this unfortunatly also doesn’t select only the country codes with NL.

Is there a way to build a postcode check that is country specific using the two input field $in.0.COUNTRY and $in.0.POSTCODE?

---

<div class="post-metadata">

### Author: ![Tomas\_Pavlas](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.cloverdx.com/tomas_pavlas/32/170_2.png) [@Tomas\_Pavlas](https://forum.cloverdx.com/u/Tomas_Pavlas)
#### Post date: [March 13, 2024, 3:41pm UTC](https://forum.cloverdx.com/t/postcode-validation/2156/2 "2024-03-13T15:41:20Z")

</div>

Hi Anouk,

In this use case, the Validator may be a less favorable way to achieve your desired functionality. The Validator is more useful in complex multi-conditional situations.

Let me suggest to you a [Simple Lookup Table](https://doc.cloverdx.com/latest/designer/lookup-tables.html#id%5Fsimple%5Flookup%5Ftable).

For instance, you can create a lookup table that can be used to check/validate the country and the postcode in combination with a LookupJoin.

Let’s presume that you have the correct values defined in a validation file as a list of country codes and regexes.

 ![](https://canada1.discourse-cdn.com/flex007/uploads/cloverdx1/original/1X/f833f7558abdfbf1d8f5ff99e4f4ce7b400c62a9.png)

You can create the **Simple Lookup:**

- Set the _validation\_file_ as the **Data source.**
- Set _countryCode_ as the **Key**.

Keep in mind that you need to create metadata for the lookup, you can create those manually or you can use a FlatFileReader to extract them from the Validation file.

 ![](https://canada1.discourse-cdn.com/flex007/uploads/cloverdx1/original/1X/8a6957a2e679028574513619772652f70b1ac8c3.png)

Now in the **[LookupJoin](https://doc.cloverdx.com/latest/designer/lookupjoin.html)** component:

- Set the _countryCode_ as the **Join key**.
- _simpleLookup0_ as the **Lookup table** _._

There are more ways to process the data, here is one of them.

In **Transform** :

- Create new Metadata with _ClientCountryCode_, _ClientID, and regexValid (note Boolean)_ **.**
- Connect the _ClientID_ and _ClientCountryCode_ with your source data that require validation.
- The _regexValid_ is defined with **matches** a function (documentation about **matches** [here](https://doc.cloverdx.com/latest/designer/string-functions-ctl2.html#id%5Fctl2%5Fmatches)). This function returns true if the ClientPostcode matches the regex returned by the lookup table.

 ![](https://canada1.discourse-cdn.com/flex007/uploads/cloverdx1/original/1X/ef3aace24b15a1aa3fa5e9c0e49762941a487a99.png)  
Now if you run the graph, all the **Valid** client country codes will be sent to _output port 0_ of the LookupJoin and all **Invalid** client country codes will be sent to the _output port 1_ with ClientIDs so you can identify them.

I added a Filter component with Filter expression:  
_//#CTL2 $in.0.regexValid == true;_

Using the same logic as the LookupJoin, the filter will divide the records by the regexValid being true or false.

 ![](https://canada1.discourse-cdn.com/flex007/uploads/cloverdx1/original/1X/c6784267ec7d60ef305dcae086daf707c4aa37f1.png)
