RegEx validate n-digit number

More
3 years 6 months ago #105316 by AndrejL
AndrejL created the topic: RegEx validate n-digit number
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
3 years 6 months ago - 3 years 6 months ago #105343 by DenisChenu
DenisChenu replied the topic: RegEx validate n-digit number
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).
An error happen ? Before make a new topic : remind the Debug mode .
Last Edit: 3 years 6 months ago by DenisChenu.

Please Log in to join the conversation.

More
3 years 6 months ago #105362 by tpartner
tpartner replied the topic: RegEx validate n-digit number
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
3 years 6 months ago #105406 by AndrejL
AndrejL replied the topic: RegEx validate n-digit number
Indeed, that works perfectly!

Please Log in to join the conversation.

Did you already participate in our customer survey?

Don't miss your chance for great prices.

Please click here to participate:

Start now

Start now!

Just create your account and start using Limesurvey today.

Register now