Welcome to the LimeSurvey Community Forum

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

Validate Subquestions?

  • iwebkat
  • iwebkat's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 8 months ago #82428 by iwebkat
Validate Subquestions? was created by iwebkat
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!
The topic has been locked.
More
11 years 8 months ago #82431 by KRav
Replied by KRav on 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
info@researchonBLOGS.de
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 8 months ago #82433 by holch
Replied by holch on topic Validate Subquestions?
I read somewhere, that this option exists in the newest version, but I can't really tell how this works.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • iwebkat
  • iwebkat's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 8 months ago #82434 by iwebkat
Replied by iwebkat on 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.
The topic has been locked.
  • iwebkat
  • iwebkat's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 years 8 months ago #82435 by iwebkat
Replied by iwebkat on 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!
The topic has been locked.
  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 8 months ago - 11 years 8 months ago #82436 by TMSWhite
Replied by TMSWhite on 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:
Code:
(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 .
Code:
{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:
Code:
{if(validation_expression,'','Please enter a valid ....')}

And here are some screen shots:







Last edit: 11 years 8 months ago by TMSWhite.
The topic has been locked.
More
11 years 8 months ago #82491 by janwillem64
Replied by janwillem64 on 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.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
11 years 8 months ago #82492 by Mazi
Replied by Mazi on 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
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 8 months ago #82505 by TMSWhite
Replied by TMSWhite on topic Validate Subquestions?
I've updated the manual here .
The topic has been locked.
More
11 years 7 months ago #84340 by debianese
Replied by debianese on 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!
The topic has been locked.
  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 7 months ago - 11 years 7 months ago #84342 by TMSWhite
Replied by TMSWhite on topic Validate Subquestions?
For 1.92, you can do this:
Code:
{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: 11 years 7 months ago by TMSWhite.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 7 months ago - 11 years 7 months ago #84367 by DenisChenu
Replied by DenisChenu on topic Validate Subquestions?
Hello,

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

And in template.css
Code:
: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 , plugin development .
I don't answer to private message.
Last edit: 11 years 7 months ago by DenisChenu. Reason: typo and code
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose