Check out the LimeSurvey source code on GitHub!

How to add regular express validation in short text input field?

More
4 years 11 months ago #73581 by Mazi

TMSWhite wrote: the preg field is question specific, so in the future, we could allow for sub-question-level validation - e.g. a different regex for each sub-question. Right now, that isn't supported. However, it would really only require a new GUI to enter sub-question-level validation (and relevance, since that is also often desired), plus minor changes to EM.

We should really put that on our list (If I remember correctly, you already have such a list?).
Because mostly, users use the multiple short text to ask for address or contact data and it really makes sense to have a validation for each field.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
4 years 11 months ago #73607 by TMSWhite
Mazi-

If we were to augment what we can do with sub-questions, I'd propose adding the following options to each sub-question. Using your example of collecting address information as multiple short text:
(1) relevance - since different sub-fields are relevant for different countries
(2) validation - since different field-types have different validation requirements
(a) we might even want conditional validation - if you wanted to have one field for postal code, but validate it differently depending upon the addresses' country.
(3) mandatory - a different set of fields is required for each type of address
(a) we might also want to consider conditional mandatory

Of course, for now, we could simply have different multiple-short-text questions to collect addresses for each country, and use relevance to pick the proper one. However, since many of the JavaScript customizations effectively try to support some of the other features described above, we may want to try to build them in.

/Tom

Please Log in to join the conversation.

More
4 years 11 months ago #73614 by Mazi
This is a good suggestion. I don't know how much effort it takes to implement some of those features based on conditions (2a and 3a of your list) and how we should deal with a possible GUI.
Depending on that effort we should maybe start small and then extend that feature for Limesurvey 2.x?
My list of priorities would read:

1. Relevance/conditions for sub-questions
2. Mandatory setting for sub-questions
3. Validations for sub-questions
4. Conditional mandatory for sub-questions
5. Conditional validation for sub-questions


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
4 years 11 months ago #73620 by Steve01
Hello,

perhaps we can use a "Show advanced subquestion settings" link like it is used in the "Show advanced settings" in the questions.

Mit freundlichen Grüßen/Best regards,

Stefan Gohlke
LimeSurvey Team

Please Log in to join the conversation.

More
4 years 11 months ago #73640 by Mazi
From a GUI point of view that is a good suggestion because only some users will use it.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
4 years 11 months ago #73645 by sammy
May I define/set the validation such as "{TOKEN:ATTRIBUTE_2} ({TOKEN:ATTRIBUTE_1})" ?
If so, give me a step of UI or hints.

Please Log in to join the conversation.

More
4 years 11 months ago #73646 by TMSWhite
The validations don't try to do substitutions like that first, since if they did, they could break regular expression validations that use embedded curly braces.

Can you give an example of why you would want to compose different regex validations using those token attributes?

Please Log in to join the conversation.

More
4 years 11 months ago #73647 by sammy
Using token attribute to validate individual invited user to input selected range/value.

Please Log in to join the conversation.

More
4 years 11 months ago #73648 by TMSWhite
Can you give a specific example? It isn't clear whether you are trying to compose a regular expression from the token attributes, or whether you are using them to specify min/max value ranges.

All of the advanced question attributes are parsed by EM, except for the regular expression validation in the core validation option. So if you want to specify min/max answers, or min/max numerical value, you can use those options.

If you really need to do dynamic regular expression validation, then you could use new the em_validation_q advanced question option. Say your regular expression pattern is composed of two attributes, you could set the em_validation_q equation to:
regexMatch(implode('',TOKEN:ATTRIBUTE_2,TOKEN:ATTRIBUTE_1),this)

where this will end up referring to the current variable name.

Please Log in to join the conversation.

More
4 years 11 months ago #73987 by sammy
Thanks your information.
Where to input/place em_validation_q advanced question option ? please advise.

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form