Validate the "Other" field

More
4 days 11 hours ago - 4 days 11 hours ago #171163 by Matadeleo
Matadeleo created the topic: Validate the "Other" field
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
regexMatch('/^(\w[-._+\w]*\w@\w[-._\w]*\w\.\w{2,3})$/', self)

Question validation tip
{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
Attachments:
Last Edit: 4 days 11 hours ago by Matadeleo.

Please Log in or Create an account to join the conversation.

More
4 days 11 hours ago - 4 days 11 hours ago #171166 by Joffm
Joffm replied the 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: 4 days 11 hours ago by Joffm.

Please Log in or Create an account to join the conversation.

More
4 days 10 hours ago - 4 days 10 hours ago #171172 by Matadeleo
Matadeleo replied the topic: Validate the "Other" field
Thanks JoffM

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

Attachments:
Last Edit: 4 days 10 hours ago by Matadeleo.

Please Log in or Create an account to join the conversation.

More
4 days 10 hours ago #171174 by Joffm
Joffm replied the 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

Please Log in or Create an account to join the conversation.

More
4 days 9 hours ago #171182 by tpartner
tpartner replied the topic: Validate the "Other" field
If using the default answer codes, it might be:

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

Please Log in or Create an account to join the conversation.

More
4 days 8 hours ago #171190 by Matadeleo
Matadeleo replied the topic: Validate the "Other" field
Thanks for the assistance guys, I'm happy with how it's working now :)

Please Log in or Create an account to join the conversation.

More
4 days 5 hours ago #171223 by DenisChenu
DenisChenu replied the topic: Validate the "Other" field

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

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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!