I want to collect ID card number for any 4 listed ID cards available to the respondents but each of the cards has different number of digits

I wish to use multiple constraints in a particular question. I want to collect ID card number for any 4 listed ID cards available to the respondents but each of the cards has different number of digits.

For example, one card is alphanumeric with 19 digits, another is number only with 11 digits. I want to ensure that the correct digits is inputted for any of the cards

Welcome to the community @Bilqis! You could do this as outlined in our support article Restricting Text Responses With Regular Expressions. As a sample workaround you could also have a look to the following community post discussed previously.

This post discussed previously should be very relevant to solve your issue:

I had used the options listed above, it isn’t working. It works for numbers only.

Specifically, I am working with 4 different cards with the following characteristics. Only one card can be selected, however, I want the specific constraints of each to apply when any of them is selected

ID Card - alphanumeric 19 digits
ID card 2 - alphanumeric with 9 digits
ID card 3 - alphanumeric with 12 digits
ID card 4 - numbers with 11 digits

Thank you

Hello @Bilqis,
You can do this by using a (cascading) if clause in your constraint, based on the selected card type (preceding select_one question).
Like:
if( ${cardType} = ‘1’, regex … A, if(${cardType} = ‘2’, regex … B, if( …, regex …C. if(…, regex D, false()) ) ) )

(You might also use 4 different ID variables, filtered by relevant clause, based on the chosen type chosen.)

1 Like

Kindly check if this constraint is in order
if(${valididtype} = ‘1’, regex(.,’^[0-9]{11}$’), if(${valididtype} = ‘2’, regex(.,’^([A-Z0-9, ,-]){1,9}$’), if(${valididtype} = ‘3’, regex(.,’^([A-Z0-9, ,-]){1,12}$’), if(${valididtype} = ‘4’, regex(.,’^([A-Z0-9, ,-]){1,19}$’), false()) ) ) )

@wroos @Kal_Lam @stephanealoo

Kindly check if this constraint is in order
if(${valididtype} = ‘1’, regex(.,’^[0-9]{11}$’), if(${valididtype} = ‘2’, regex(.,’^([A-Z0-9, ,-]){1,9}$’), if(${valididtype} = ‘3’, regex(.,’^([A-Z0-9, ,-]){1,12}$’), if(${valididtype} = ‘4’, regex(.,’^([A-Z0-9, ,-]){1,19}$’), false()) ) ) )

@Bilqis, you could do it as outlined in the image shared below:

In the survey tab of your XLSForm:

In the choices tab of your XLSForm:

Image 2

Data entry screen as seen in Enketo: when everything is OK

Data entry screen as seen in Enketo: when a wrong entry is made

Reference XLSForm:

Regex.xlsx (12.8 KB)