Validating age question based on an earlier question on Gender

Hey Team,

I am trying to add custom validation to age based on an earlier question on gender. If female is selected then the age should be 12-35 but if male is selected then the age should be 15-17.

I have tried (${member_gender}=1 and .=>12 and .<=35) or (${member_gender}=2 and .=>15 and .<=17) in the custom validation but not working.

Kindly help.

Could you explain more, please?

Try to use string-format here: ${member_gender}=β€˜1’ …
member_gender is probably a select_one type, i.e. values are stored as string.

1 Like

Yes the gender is a select one., with option of either female or male. The other question is asking of age (number). I want to set validation on age that if female is selected earlier then age should be 12-35 and if male was selected then age should be 12-17.

I have tried using quotes (string) : (${member_gender}=β€˜1’ and .=>12 and .<=35) or (${member_gender}=β€˜2’ and .=>15 and .<=17)

but the validations is not working.

What happens?

Did you check the form with the online validator?

1 Like

It is a simple syntax error: greater-equal is >= (not => as you wrote).

Would you mind, please, to check your forms with the online validator during development (and preferably, also before posting). It would have marked the following error:


(You get the same error if you try to deploy your form in KoboToolbox. It’s even a bit strange that you can Preview in KoboToolbox and Formbuilder without error message,)

In case you use the Formbuilder for development, you can easily download the form as XLSForm and upload it into the online validator for testing. (You can also use the Preview function there,)

To locate a problem, it is often helpful to strip down an expression (or a form) in simple elements, e.g. here just: . . => 12, which will already indicate the problem.
image

1 Like

Thank you so much, I have changed the operator signs and it has worked. Thank you again.

1 Like

@wroos, @chalasah :clap: :heart: :partying_face: