Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Validate Subquestions?

Validate Subquestions? 1 year 10 months ago #82428

  • iwebkat
  • iwebkat's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 11
  • Karma: 0
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 administrator has disabled public write access.

Re: Validate Subquestions? 1 year 10 months ago #82431

  • ResearchOnBlogs
  • ResearchOnBlogs's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 184
  • Thank you received: 16
  • Karma: 8
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.
The administrator has disabled public write access.

Re: Validate Subquestions? 1 year 10 months ago #82433

  • holch
  • holch's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2451
  • Thank you received: 256
  • Karma: 94
I read somewhere, that this option exists in the newest version, but I can't really tell how this works.
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
The administrator has disabled public write access.

Re: Validate Subquestions? 1 year 10 months ago #82434

  • iwebkat
  • iwebkat's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 11
  • Karma: 0
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 administrator has disabled public write access.

Re: Validate Subquestions? 1 year 10 months ago #82435

  • iwebkat
  • iwebkat's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 11
  • Karma: 0
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 administrator has disabled public write access.

Re: Validate Subquestions? 1 year 10 months ago #82436

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 81
  • Karma: 36
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_sub-questions.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:

validation-name.jpg


validation-invalid-both.jpg


validation-valid-both.jpg


validation-invalid-phone.jpg
Last Edit: 1 year 10 months ago by TMSWhite.
The administrator has disabled public write access.

Re: Validate Subquestions? 1 year 10 months ago #82491

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 administrator has disabled public write access.

Re: Validate Subquestions? 1 year 10 months ago #82492

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5279
  • Thank you received: 289
  • Karma: 246
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)limesurvey.org'"
The administrator has disabled public write access.

Re: Validate Subquestions? 1 year 10 months ago #82505

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 81
  • Karma: 36
I've updated the manual here.
The administrator has disabled public write access.

Re: Validate Subquestions? 1 year 8 months ago #84340

  • debianese
  • debianese's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 1
  • Karma: 0
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 administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.310 seconds
Donation Image