Calculate number as only some particular digits of other answer

Hello everyone,

I am trying to create a constraint in a field where it only allows to advance to the next question if the value introduced is contained in a previous question's answer.

More specifically, I will have two integer questions. One would be: "ID Number" (3 digits) and the other one would be "HH ID Number" (5 digits). I need the HH ID Number to be "Xid_numberX" where X are other integers and "id_number" is the previously introduced "ID Number".

So the constraint will allow the user to advance only if the value of id_number is the 3 middle digits of the "hh_id_number".

Example.

ID Number = 009
HH ID Number = 10091

If I try to insert the HH ID Number as 10081, it won't allow me to continue because it does not match the ID number - 009.

Hope the question makes sense and there is a way to implement it.

Best regards,
Francisco

Try this:

HH_ID: constraint="substr(${HH_ID},1,4)=${ID}"

Where ${ID} is your ID_Number field (ie "009" above). See substr() function for details. Note string indexing starts with 0 being first character (hence 1), and the end is the index of the character after the last one you want (hence 4).

I will have two integer questions. One would be: "ID Number" (3 digits) and the other one would be "HH ID Number" (5 digits).

BTW you may want to explicitly enforce these pre-conditions, and for this work these fields probably need to be Text, otherwise "001" will be stored as "1" if its typed as an Integer.

1 Like

Thank @Xiphware,

Works as needed.