Welcome, Guest
Username: Password: Remember me

TOPIC: Validation: Ensuring two answers match

Validation: Ensuring two answers match 1 year 2 months ago #96392

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 196
  • Thank you received: 5
  • Karma: 5
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
The administrator has disabled public write access.

Validation: Ensuring two answers match 1 year 2 months ago #96408

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6226
  • Thank you received: 792
  • Karma: 238
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)
Last Edit: 1 year 2 months ago by DenisChenu.
The administrator has disabled public write access.

Validation: Ensuring two answers match 1 year 2 months ago #96433

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 196
  • Thank you received: 5
  • Karma: 5
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
The administrator has disabled public write access.

Validation: Ensuring two answers match 1 year 2 months ago #96434

  • holch
  • holch's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2562
  • Thank you received: 291
  • Karma: 106
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.
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.

Validation: Ensuring two answers match 1 year 2 months ago #96435

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6226
  • Thank you received: 792
  • Karma: 238
Last Edit: 1 year 2 months ago by DenisChenu.
The administrator has disabled public write access.

Validation: Ensuring two answers match 1 year 2 months ago #96439

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 196
  • Thank you received: 5
  • Karma: 5
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)?
The administrator has disabled public write access.

Validation: Ensuring two answers match 1 year 2 months ago #96442

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 196
  • Thank you received: 5
  • Karma: 5
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: 1 year 2 months ago by dweisser. Reason: Solved
The administrator has disabled public write access.
The following user(s) said Thank You: Ben_V
Moderators: ITEd
Time to create page: 0.219 seconds
Donation Image