Welcome to the LimeSurvey Community Forum

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

Multiple short text regex validation

  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
7 years 4 weeks ago - 7 years 4 weeks ago #151766 by Matadeleo
Multiple short text regex validation was created by Matadeleo
Hi,

I'm trying to validate the inputs for a multiple short text question in my survey.

The question requires an answer:

- Between 2 and 3 characters long
- The first character is always capital and an alphabetical character
- The second and third characters are always digits
- All sub-questions must be subject to the same validation

Example acceptable inputs:

- A1
- B10
- C16

Rejected inputs:

- 1A
- A1A
- CC1

I've made a regular expression to match these:
Code:
/([A-Z]{1}\d{1,2})/g

A-Z{1} - 1 capital letter
\d{1,2} - 1 or 2 digits

I've tested that my inputs are being correctly matched using regexr.com however, when putting it into LimeSurvey, my condition is returning as FALSE.

Here is an example:

File Attachment:

File Name: validate.lss
File Size:16 KB
Attachments:
Last edit: 7 years 4 weeks ago by Matadeleo.
The topic has been locked.
More
7 years 4 weeks ago #151779 by jelo
Replied by jelo on topic Multiple short text regex validation
What LimeSurvey version is used?

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
More
7 years 4 weeks ago - 7 years 4 weeks ago #151783 by jelo
Replied by jelo on topic Multiple short text regex validation
Expression flags (Parameter after the last /) are often a source of trouble in LimeSurvey.

The Expression manager is fine with
regexMatch('/([A-Z]{1}\d{1,2})/', Q1_1)
but marks a faulty regex when using your valid term:
regexMatch('/([A-Z]{1}\d{1,2})/g', Q1_1)

We had some issues with /i in this thread.
www.limesurvey.org/forum/can-i-do-this-w...nce-equations#149434
The last status was that the fix was working. But is was about the on-page javascript regex validation.


The /g flag might be not supported by the used php function.
PHP has a special function preg-match-all for global regex.
php.net/manual/en/function.preg-match-all.php

The g flag is causing the error.



Might be the preg-match-all function.
php.net/manual/en/function.preg-match-all.php

Perhaps it is a worth a bugreport. Perhaps I have overlooked something. Let's see what others are thinking.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Last edit: 7 years 4 weeks ago by jelo.
The following user(s) said Thank You: Matadeleo
The topic has been locked.
  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
7 years 3 weeks ago #151818 by Matadeleo
Replied by Matadeleo on topic Multiple short text regex validation
Thanks for this Jelo, all working now. Would have been scratching my head for days on that one :)
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose