Limiting the inputted digit

Greeting
I want to limit the inputted text to one digit only. I have tried to restrict using diffrent methods like regex(.,'....) but i can't . I need help on this issue.
Attached the document.FFQ_V.xls (63.5 KB)

Dear @amen13

You have to rename the column header from constraints to constraint, this will fix the issue.

regards,

Dear @amen13

You have to rename the column header from constaraints to "constraint", this will fix the issue.

attached is a working form.
FFQ_V1.xls (66 KB)
regards,

1 Like

Greeting
Thsnk you for your support but still it is not solved.
Can any one support me?FFQ_V.xls (61.5 KB)

Hi @amen13,

I've tested the file uploaded by @rassam, and the constraints seems to work as expected.
I've tested it here.
https://odk.enke.to/preview?form=https://xlsform.opendatakit.org/downloads/n_w3svt3/FFQ_V1.xml

Can you clarify which part is giving you problems?

Thank you,
Andrea

1 Like

@andrea

I want to restrict the digit which means on the text part the data collectors has to be fill only one digit(0 or 1 or 2....). but still it accept whatever you write (number) i.e still there is no restriction digit. Please see the form which i uploaded today.

Dear @amen13

This is the form i have modified and its working.

FFQ_V1.xls (66 KB)

1 Like

Dear @amen13

If you want the text to accept only 0,1,2 values, the constraint should be in this form: regex(.,'^[0|1|2]{1}$' )

Regards,

1 Like

Hi @amen13

The initial error in your form was the name of the constraint field (you had a typo there).
@rassam kindly helped you fix it.

I have checked both the file he uploaded

And the latest one you uploaded.

I tested both of them on Enketo, and they work as expected (only allowing to enter a single digit value).

Note that:

  • initially some of your variables allowed for double digits, and @rassam preserved this requirement in the first reply;
  • the condition "and (.>=0)" in your constraint field is redundant.

FYI the '{1}' is actually redundant; '^[0|1|2]$' would suffice.

2 Likes

Hi @Xiphware

Yes, you are right, I missed it.