Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: RegEx validate n-digit number

RegEx validate n-digit number 2 years 5 months ago #105316

  • AndrejL
  • AndrejL's Avatar
  • Offline
  • Junior Lime
  • Posts: 39
  • Karma: 1
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 administrator has disabled public write access.

RegEx validate n-digit number 2 years 5 months ago #105343

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9254
  • Thank you received: 1319
  • Karma: 382
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 developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
Last Edit: 2 years 5 months ago by DenisChenu.
The administrator has disabled public write access.

RegEx validate n-digit number 2 years 5 months ago #105362

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6111
  • Thank you received: 1356
  • Karma: 532
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 administrator has disabled public write access.
The following user(s) said Thank You: DenisChenu, AndrejL

RegEx validate n-digit number 2 years 5 months ago #105406

  • AndrejL
  • AndrejL's Avatar
  • Offline
  • Junior Lime
  • Posts: 39
  • Karma: 1
Indeed, that works perfectly!
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.215 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form