Sometimes validation rules require multiple inputs to provide a pass/fail result, so it is often easier to build and understand the code if it is written using Java.
If you aren't familiar with code routines in Talend, it is recommended that you first complete the recipe Creating custom functions using code routines, Chapter 5 , Using Java in Talend that will take you through the setup of code routines.
Create a new code routine called
validation
, and copy the following code into it:/** * validateCustomerAge: Check customer is 18 or over for UK, 21 or over for rest of world. * returns true if valid, false if invalid * e.g. validateCustomerAge(23,"UK") * * {talendTypes} Boolean * * {Category} Validation * * {param} string(age) input: Customer age * {param} string(country) input: Customer country ...