Validate Subquestions?

More
5 years 6 days ago #82428 by iwebkat
iwebkat created the topic: Validate Subquestions?
I have used multiple short answers for a section including gathering name, email, phone, etc. Is there a way to add validation to these individual subquestions? I know regular expressions can be used for email addresses, zip codes, and phone numbers, but I haven't found a way to implement this.

I have been searching the manual, and have found the regular expression codes, but cannot find where exactly to put them to make them work.

Any pointers would be greatly appreciated. Thanks in advance!

Please Log in to join the conversation.

More
5 years 6 days ago #82431 by KRav
KRav replied the topic: Validate Subquestions?
as far as I know it's not possible. I would use single questions.


research on BLOGS - Professional LimeSurvey support
Consultant - Templates - Training - JQuery magic - Support - Coding - Survey creation and more..

Contact
Professional LimeSurvey support
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in to join the conversation.

More
5 years 6 days ago #82433 by holch
holch replied the topic: Validate Subquestions?
I read somewhere, that this option exists in the newest version, but I can't really tell how this works.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
5 years 6 days ago #82434 by iwebkat
iwebkat replied the topic: Validate Subquestions?
Thanks...if I can't figure out the sub-question route then I'll definite do this. It's nice to know it just isn't there.

Please Log in to join the conversation.

More
5 years 6 days ago #82435 by iwebkat
iwebkat replied the topic: Validate Subquestions?
I just upgraded to the newest version, but I can't see where to validate subquestions. If you have any idea where to point me, I'll be happy to try.

Thanks!

Please Log in to join the conversation.

More
5 years 6 days ago - 5 years 6 days ago #82436 by TMSWhite
TMSWhite replied the topic: Validate Subquestions?
The optimal way to validate sub-questions has not been implemented. Ideally, there would be a regex validation equation per sub-question so you could have different ones for each part of a multiple-short text. That doesn't exist yet (and probably won't for quite a while unless you know of volunteers with time to implement it).

However, you can fake it using the Whole question validation and Tip for whole question validation options.

Here is a working example.

File Attachment:

File Name: validate_s...ions.lss
File Size:21 KB


Say your question is "q1", and your sub-questions are "name", "email", and "phone", you could set the Whole question validation to:
(is_empty(q1_email) or regexMatch('/(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})/', q1_email))
 and 
(is_empty(q1_phone) or regexMatch('/^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/', q1_phone))

This will ensure that the user enters a valid email and phone number (in this case, a non-answer is also accepted via is_empty()).

Then, to tailor the validation message, you would use this for the Tip for whole question validation .
{if((is_empty(q1_email) or regexMatch('/(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})/', q1_email)), '', 'Please enter a valid email address.<br />')}
{if((is_empty(q1_phone) or regexMatch('/^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/', q1_phone)), '', 'Please enter a valid phone number.')}

As you can see, you are using the exact same validation expression for q1_email and q1_phone, you're just surrounding it with:
{if(validation_expression,'','Please enter a valid ....')}

And here are some screen shots:







Last Edit: 5 years 6 days ago by TMSWhite.

Please Log in to join the conversation.

More
5 years 5 days ago #82491 by janwillem64
janwillem64 replied the topic: Validate Subquestions?
Hello TMSWhite, Got it!! For the others with same issue. Go to question. Go to advanced settings. Fill in the validation in 'Question validation equation' and the tip in 'Question validation tip'. The tip validates the same and shows the error message. q1 is your question code and email is sub question code. Good luck. And thanks TMSWhite.

Please Log in to join the conversation.

More
5 years 5 days ago #82492 by Mazi
Mazi replied the topic: Validate Subquestions?

janwillem64 wrote: Hello TMSWhite, Got it!! For the others with same issue. Go to question. Go to advanced settings. Fill in the validation in 'Question validation equation' and the tip in 'Question validation tip'. The tip validates the same and shows the error message. q1 is your question code and email is sub question code. Good luck. And thanks TMSWhite.

Please add a note to the manual as well so other benefit from the findings, too.


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
5 years 5 days ago #82505 by TMSWhite
TMSWhite replied the topic: Validate Subquestions?
I've updated the manual here .

Please Log in to join the conversation.

More
4 years 10 months ago #84340 by debianese
debianese replied the topic: Validate Subquestions?
Thanks! This topic has helped me a lot!

But I have another question: How can you localize the error message?
I have to create a survey in german and english. The error message should be in the selected language!

Please Log in to join the conversation.

More
4 years 10 months ago - 4 years 10 months ago #84342 by TMSWhite
TMSWhite replied the topic: Validate Subquestions?
For 1.92, you can do this:
{if(validation_expression,'',if(LANG=='en','Please enter a valid ....','Bitte antworten ...'))}

For 2.0, I'd recommend making this field one of those that can be translated into multiple languages via the quick translation feature.
Last Edit: 4 years 10 months ago by TMSWhite.

Please Log in to join the conversation.

More
4 years 10 months ago - 4 years 10 months ago #84367 by DenisChenu
DenisChenu replied the topic: Validate Subquestions?
Hello,

Can use pseudo class lang too in template.css:
<span lang="en">'Please enter </span><span lang="de">Bitte antworten</span>

And in template.css
:lang(en) :lang(de){display:none}
:lang(de) :lang(en){display:none}

Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Last Edit: 4 years 10 months ago by DenisChenu. Reason: typo and code

Please Log in to join the conversation.

More
4 years 9 months ago #85375 by Bitbull
Bitbull replied the topic: Validate Subquestions?
Sorry to dig up this (old) thread, but I've got a serious problem with validation of subquestions. I've attached my survey here (sorry, it's in Dutch, but easy to understand as I've stripped it down to the problematic question).
I really don't see why I can't get past the question (when testing the whole survey, that seems to be impossible, a message keeps popping up). Regular expressions have been validated, everything seems fine with "realtime validation", but impossible to get past the question.
Could you guys please take a look and tell me what I'm doing wrong?
Thanks in advance!
Attachments:

Please Log in to join the conversation.

More
4 years 9 months ago #85442 by Bitbull
Bitbull replied the topic: Validate Subquestions?
Okay, I already found the solution.
Apparently, regular expressions in LimeSurvey need to start & end with / character.
It was possible to notice in the example, but I found it nowhere clearly stated, only here (point 2)

Please Log in to join the conversation.

More
4 years 9 months ago #85482 by Mazi
Mazi replied the topic: Validate Subquestions?
If you are missing this information at our manual, please add it there. It's a wiki, everyone can edit it.

You can also post a feature request at our idea tracker to add some JavaScript validation before saving a regular expression. Such a script can check for the first characters and throw an error.


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.

Start now!

Just create your account and start using Limesurvey today.

Register now