Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

RegEx validate n-digit number

  • AndrejL
  • AndrejL's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 3 weeks ago #105316 by AndrejL
RegEx validate n-digit number was created 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
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 3 weeks ago - 10 years 3 weeks ago #105343 by DenisChenu
Replied by DenisChenu on topic RegEx validate n-digit number
Hi,

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

But, maybe:
Code:
/^([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 , plugin development .
I don't answer to private message.
Last edit: 10 years 3 weeks ago by DenisChenu.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 3 weeks ago #105362 by tpartner
Replied by tpartner on topic RegEx validate n-digit number
I think that will allow a 15-digit number or a 9-digit number.

How about:
Code:
/^([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
The topic has been locked.
  • AndrejL
  • AndrejL's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 3 weeks ago #105406 by AndrejL
Replied by AndrejL on topic RegEx validate n-digit number
Indeed, that works perfectly!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose