Welcome to the LimeSurvey Community Forum

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

Input Validation with regular expression fails

  • Bielefeld
  • Bielefeld's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 1 month ago - 7 years 1 month ago #149223 by Bielefeld
Hi,

I can't seem to get this working with the current LS Version 2.63.1+170305

Trying to validate input values (numeric or alphanumeric) via the "Validation"-Field
in Question-Editor. I try to use regular expressions, but even the simplest currently fail.

Example:
This expression should allow only *one* alphanumerical letter in lowercase (a-z),
and I specified the maximum occurrence of *one* character explicitly using {1}
Code:
/^([a-z]{1})$/

Of course, when I enter a number or a non-alphabetical character, the answer-box
gets a red frame, showing this is not correct. Okay. Now I enter a alphabetical letter
like "a": Okay! But when I continue entering more letters (or even numbers etc.), the
answer is still marked as correct, so no red frame anymore after the first correct letter.

In my opinion this behaviour is incorrect. I have tested this simple regex with some
online regex-machines (e.g.: regex101.com), and with these, my regex rules were okay -
for this example: one alpha letter was accepted, more than one were rejected.

I have played with many more regex rules, simple or more complex, and the current
regex validation mode of LS does not seem to work for me. Any suggestions?

Cheers,
Stefan

Version 2.63.1+170305
Last edit: 7 years 1 month ago by Bielefeld. Reason: typo
The topic has been locked.
More
7 years 1 month ago #149224 by jelo
Are you using your template modifications as stated in this thread:
www.limesurvey.org/forum/design-issues/1...-the-question#149217
Code:
  .em_regex_validation.emtip.good
  {
    display:none;
  }
 .em_regex_validation.emtip.error
  {
    display:none;
  }

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • Bielefeld
  • Bielefeld's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 1 month ago #149225 by Bielefeld
Replied by Bielefeld on topic Input Validation with regular expression fails
Yes, I do. But with my example case, e.g. entering a "1" (numeric value)
I would still have this correctly classified as an error, so a red frame
around the incorrect answer will be displayed, see attachment...

Thanks for your input!

Version 2.63.1+170305
The topic has been locked.
  • Bielefeld
  • Bielefeld's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 1 month ago #149226 by Bielefeld
Replied by Bielefeld on topic Input Validation with regular expression fails
Just cross checking:
Same regex behaviour with the original default template.
Any ideas?

Version 2.63.1+170305
The topic has been locked.
More
7 years 1 month ago #149227 by jelo

Bielefeld wrote: Just cross checking:
Same regex behaviour with the original default template.
Any ideas?

This looks like a bug in the Javascript-Validation. I'm not a RegEx-Expert but this look alright to me.
LimeSurvey is always doing validation on JS and PHP-Level.

So if you are executing your survey (instead of preview) the validation might be at least executed correctly on PHP level. You could try that and then submit a bugreport about your findings. It should be work on JS-Level. Perhaps the {} are now causing trouble after some regression in the code. We will see.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • Bielefeld
  • Bielefeld's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 1 month ago #149228 by Bielefeld
Replied by Bielefeld on topic Input Validation with regular expression fails
Thanks for your input!

Executing the survey live does not make any difference,
simplifying the regex to the absolute minimum like this:
Code:
/^[a-z]$/
does not make a difference either.

Your point of JS vs. PHP regex-validation is not clear to
me. Is it, that on some levels (preview perhaps) JS-regex
is used, and on other (live survey) PHP-regex is used?
This is not how I tried to understand the source code,
but I may be missing something important here!

Cheers,
Stefan

Version 2.63.1+170305
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 1 month ago #149255 by tpartner
Replied by tpartner on topic Input Validation with regular expression fails
Please file a bug report supplying all details and a small test survey.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
7 years 1 month ago #149277 by jelo

Bielefeld wrote: Your point of JS vs. PHP regex-validation is not clear to
me. Is it, that on some levels (preview perhaps) JS-regex
is used, and on other (live survey) PHP-regex is used?

Validation on page via JS (in the browser) and validation after hitting a button to submit page via PHP (on the server). The JS validation seems to be not working with your RegEx. I wondered what happen, when you enter a invalid answer (which isn't prevented by the JS-validation) and submit it to the server.
Will LS accept it or will LS trigger an error and enforce you to change the answer to comply to your RegEx.

The bugreport should be submitted either ways. Since if JS is available we want to catch these things on browser level.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • Bielefeld
  • Bielefeld's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 1 month ago - 7 years 1 month ago #149313 by Bielefeld
Replied by Bielefeld on topic Input Validation with regular expression fails
Thanks for your input!

It seems the error is on the JS side, since after activating
the survey and entering invalid data (being accepted by
the JS regex check), the server's answer is indeed, that
the data is not valid and should be changed. Good hint
to check that!

I have created a bug report as recommended
and attached a sample LS-export to reproduce.

Bugreport

In the below attachment you will find the same LS export
so you can test and maybe reproduce the effect with your system.

Cheers,
Stefan

Version 2.63.1+170305
Last edit: 7 years 1 month ago by Bielefeld. Reason: typo
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose