Check out the LimeSurvey source code on GitHub!

RegEx validate n-digit number

More
2 years 11 months ago #105316 by AndrejL
Hi!

I would like LS to validate entry of a certain n-digit number (card id number9. For my case it must be a 15-digit number. But respondent must also have an option to enter just number 9 (if he doesn't know his card id number).

So only valid answers are digit 9 or any 15-digit number.

LS version on which survey is running is 1.91+.

I'm am aware of RegEx for 15-digit number /[0-9]{15}/ but I don't know how to let user to be able to enter digit 9 as well.

Thank you,

Andrej

Please Log in to join the conversation.

More
2 years 11 months ago - 2 years 11 months ago #105343 by DenisChenu
Hi,

Not sure (i'm not a regexp expert ...)

But, maybe:
/^([0-9]{15}|[0-9]{9})$/

Denis
PS: oups, Tony read question better than me, my english is very poor ....

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
Last Edit: 2 years 11 months ago by DenisChenu.

Please Log in to join the conversation.

More
2 years 11 months ago #105362 by tpartner
I think that will allow a 15-digit number or a 9-digit number.

How about:
/^([0-9]{15}|9)$/


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu, AndrejL

Please Log in to join the conversation.

More
2 years 11 months ago #105406 by AndrejL
Indeed, that works perfectly!

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form