Check out the LimeSurvey source code on GitHub!

Validation: Ensuring two answers match

More
3 years 8 months ago #96392 by dweisser
Hello LS Team,

I have a question.

1) I want to ask participants to enter his/her email and then enter it again, to confirm it was entered correctly.

I have been reading about question level validation: manual.limesurvey.org/Question_type_-_Sh...28preg_validation.29

But, I cannot figure out how to compare the values from one question to another question using the validation functions. I know this can be done with the Expression Manager, but to my mind this is a bit clunky. I would have to use a boilerplate question as a custom warning message if the emails didn't match and set a condition not to allow the participant to submit the survey unless the two email questions match.

Can the question validation functionality be used to accomplish this? Is there a better solution?

Nebraska David

Please Log in to join the conversation.

More
3 years 8 months ago - 3 years 8 months ago #96408 by DenisChenu
With a multi text question:

Question validation :
MAIL_MAIL==MAIL_CONF
Question text validation
regexMatch("/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})?$/",MAIL_MAIL)

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).
Last Edit: 3 years 8 months ago by DenisChenu.

Please Log in to join the conversation.

More
3 years 8 months ago #96433 by dweisser
Hey this looks promising.

Steps I followed:
1) create a multiple short-text question with two sub questions.
- Code: EmailField1 "Enter your email address"
- Code: EmailField2 "Re-enter your email address.

2) When you edit the question, at the bottom of the screen you see a field called "Validation" directly below the relevance equation. There I entered: MAIL_MAIL==MAIL_CONF

3) In advanced settings, under Logic, in the field marked Question Validation Equation, I entered: regexMatch("/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})?$/",MAIL_MAIL)

I tested the survey, and no flag of any kind indicates that the two emails don;t match. Where did I go wrong?

Also, can I add validation to ensure that the emails are valid emails?

Thank you for any further advice. As always.
David

Please Log in to join the conversation.

More
3 years 8 months ago #96434 by holch
the validation field should not be able to process calculations or more complicated formulations, only regex.

So you probably have to put the regex into the the validation field and the comparision into the validation equation field.

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
3 years 8 months ago - 3 years 8 months ago #96435 by DenisChenu

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).
Last Edit: 3 years 8 months ago by DenisChenu.

Please Log in to join the conversation.

More
3 years 8 months ago #96439 by dweisser
This is great. Thanks Denis and Holch.

Last hurdle. I only want to show the validation tip(s) "Please enter a valid email" if the user violates the validation equation.

So, I put this in the sub-question validation tip box like it shows in the manual:

if(regexMatch("/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})?$/",MAIL_MAIL),'Notip will show', 'Bad')

but all it does is print the validation equation on the survey where the tip should be.

What do you think I'm doing wrong (now)?

Please Log in to join the conversation.

More
3 years 8 months ago - 3 years 8 months ago #96442 by dweisser
I found another related post from tpartner that seems on point...

www.limesurvey.org/en/forum/can-i-do-thi...l-verification#95147

SOLVED:
I realized you can have multiple conditions on the validation tip written in separate statements.

So, in the question validation tip, I have:
{if(MAIL_MAIL != '' && MAIL_CONF != '', '', 'Enter your email twice.')}
{if(MAIL_MAIL != MAIL_CONF, 'The emails must match.', '')}
{if(regexMatch("/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})?$/",MAIL_MAIL), '', 'Invalid Email')}

I hope it helps someone out. Thanks again,
David
Last Edit: 3 years 8 months ago by dweisser. Reason: Solved
The following user(s) said Thank You: Ben_V

Please Log in to join the conversation.

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