Restrict for Entering 10, 13 OR 17 digit number only

I want to restrict for Entering 10, 13 and 17 digit number only. Using regex(., ‘^[0-9]{10}$’) and regex(., ‘^[0-9]{13}$’) and regex(., ‘^[0-9]{17}$’) but not working.

Welcome to the community @milon! Do you mean you wish to enter an input with only 10 or 13 or 17?

10, 13 and 17 digit length number only except other lenght digit.

10 digit length? 13 digit length and 17 digit length?

Yes that i mean

This is a bit confusing, do you mean it can be either 10 or 13 or 17 in length and not 10 and 13 and 17

Yes this can be either 10 or 13 or 17 in length

1 Like

Try changing the above to either of the two
Option 1
regex(., ‘^[0-9]{10}$’) or regex(., ‘^[0-9]{13}$’) or regex(., ‘^[0-9]{17}$’)

Option 2
regex(., ‘^([0-9]{10}|[0-9]{13}|[0-9]{17})$’)

1 Like

Great ! Option 1 is working thanks for your cooperation

You are welcome. Did you try option 2?

yes but not working.

Another one question how can I check duplicate entry of a number from ODK Collect Apps

Corrected Option 2 to be a much neater version compared t o Option 1
regex(., ‘^([0-9]{10}|[0-9]{13}|[0-9]{17})$’)

2 Likes

On the issue of duplicate entry, this is not possible as has been previously discussed within the forum

1 Like

Ok thanks for your response.

1 Like

Hello @stephanealoo,
Nice example (with grouping and or), to add in the KoBo help documentation?
Kind regards

2 Likes

Hi @wroos
Definitely we do have lots of additional insights that come from the shared experience by users. We will strive to update our article with the AND & OR combination for regex. Thanks so much.

Stephane

2 Likes

Hi Stephanealoo,
Limiting the response number to exactly 17 digit is not working for me here. It is an integer type question. I have to limit it to the exactly 17 digit. I have used the regex formula exactly as you stated. My formula look like this;
regex(.,’^[0-9]{17}$’)
Do not know why, but this is not working for me? Can you please suggest? Thanks in advance.

@tasfik_rukan, your question type should be text. It should then work. You will also need to change the appearance to numbers.

1 Like

See
https://community.kobotoolbox.org/t/the-regex-function-does-not-work-in-my-form/9786/5.

Please, avoid posting the same question in the forum twice.

1 Like