Multiple short text regex validation

More
2 years 4 months ago - 2 years 4 months ago #151766 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:
/([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: 2 years 4 months ago by Matadeleo.

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
2 years 4 months ago #151779 by jelo
What LimeSurvey version is used?

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Please Log in or Create an account to join the conversation.

More
2 years 4 months ago - 2 years 4 months ago #151783 by jelo
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
Attachments:
Last edit: 2 years 4 months ago by jelo.
The following user(s) said Thank You: Matadeleo

Please Log in or Create an account to join the conversation.

More
2 years 4 months ago #151818 by Matadeleo
Thanks for this Jelo, all working now. Would have been scratching my head for days on that one :)

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!