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 9 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 9 months ago #105343

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9586
  • Thank you received: 1375
  • Karma: 390
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 (use private message).
Last Edit: 2 years 9 months ago by DenisChenu.
The administrator has disabled public write access.

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

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6574
  • Thank you received: 1477
  • Karma: 579
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 9 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.
Time to create page: 0.220 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form