Welcome to the LimeSurvey Community Forum

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

Validate the "Other" field

  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 9 months ago - 5 years 9 months ago #171163 by Matadeleo
Validate the "Other" field was created by Matadeleo
Hi, I'm wondering if it's possible to validate my "other" box -



Here is the code I would use for this if I were validating a question or subquestion:

Question validation equation
Code:
regexMatch('/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})$/', self)

Question validation tip
Code:
{if(regexMatch('/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})$/',self),"Email validated","Please enter a valid email address")}

In this case, I believe instead of targeting self - we would need to target something like "Q1_other.shown" - but I think this solution would need some kind of JavaScript solution?


File Attachment:

File Name: OtherValidation.lss
File Size:13 KB
Last edit: 5 years 9 months ago by Matadeleo.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago - 5 years 9 months ago #171166 by Joffm
Replied by Joffm on topic Validate the "Other" field
Hi,
no JS needed.

Activate your survey, enter the data and submit.
Look at the answers and you will see how this "open ends" are saved. (as "Q1_other")

Now you can include this in your "regexMatch('/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})$/', Q1_other)
and add the condition
that !is_empty(Q1_other)
or Q1=="-oth-"


Example:
equation:
(regexMatch('/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})$/', Q1_other)) and (!is_empty(Q1_other))

Tip:
{if((!regexMatch('/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})$/', Q1_other)) and (!is_empty(Q1_other)),"Please, corrrect Email","")}
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 5 years 9 months ago by Joffm.
The topic has been locked.
  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 9 months ago - 5 years 9 months ago #171172 by Matadeleo
Replied by Matadeleo on topic Validate the "Other" field
Thanks JoffM

It seems the code is currently triggering when we don't want it to, see screenshot below:

Last edit: 5 years 9 months ago by Matadeleo.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago #171174 by Joffm
Replied by Joffm on topic Validate the "Other" field
You see, what is missing?

regexMatch('/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})$/', Q1_other)) and (!is_empty(Q1_other)) or (Q1==1)

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: Matadeleo
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago #171182 by tpartner
Replied by tpartner on topic Validate the "Other" field
If using the default answer codes, it might be:

Code:
regexMatch('/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})$/', Q1_other)) AND (!is_empty(Q1_other)) OR (Q1=="A1")

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Matadeleo
The topic has been locked.
  • Matadeleo
  • Matadeleo's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 9 months ago #171190 by Matadeleo
Replied by Matadeleo on topic Validate the "Other" field
Thanks for the assistance guys, I'm happy with how it's working now :)
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago #171223 by DenisChenu
Replied by DenisChenu on topic Validate the "Other" field

tpartner wrote: If using the default answer codes, it might be:

Code:
regexMatch('/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})$/', Q1_other)) AND (!is_empty(Q1_other)) OR (Q1=="A1")

Since there are .social , .anything etc domain now, need to be updated to
regexMatch('/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,63})$/', Q1_other))

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.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose