Welcome to the LimeSurvey Community Forum

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

Help with email validation script - it wont work

  • matthe81
  • matthe81's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 2 months ago #227729 by matthe81
Please help us help you and fill where relevant:
Your LimeSurvey version: Version 5.3.9+220411
Own server or LimeSurvey hosting: shared hosting provider / community edition
Survey theme/template: Fruity Theme

==================
Hi I have an issue of email-validation script I found, I think its few years old but anyway... I am newbe to making surveys so bare with me. It might not be a new topic for all of you that got a hang of it

I have simply two Multiple short text (Type: Q) to comfirm an input of emailaddress, but it will not confirm its correct. I need a little assistance to make it work, I dont understand whats wrong..

RegExp:
Code:
/^.?@.?\..+$/

Sub-question validation equation:
Code:
(!is_empty(this.NAOK =='SQ001') AND regexMatch('/^.?@.?\..+$/',this.NAOK =='SQ001') AND (!is_empty(this.NAOK =='SQ002') or regexMatch('/^.?@.?\..+$/',this.NAOK =='SQ002')) AND (this.NAOK =='SQ001' == this.NAOK =='SQ002'))

Sub-question validation tip:
Code:
{if(is_empty(this.NAOK =='SQ001') or regexMatch('/^.+?@.+?\..+$/',this.NAOK =='SQ001'),'','Please enter a valid email address.')}
{if(is_empty(this.NAOK =='SQ002') or regexMatch('/^.+?@.+?\..+$/',this.NAOK =='SQ002'),'','Please verify the email address.')} {if(!is_empty(this.NAOK =='SQ001') AND !is_empty(this.NAOK =='SQ002') AND (this.NAOK =='SQ001' == this.NAOK =='SQ002'), 'Email addresses match!', 'Email addresses do NOT match!')}

Thanks in advanced!

Please Log in to join the conversation.

More
2 years 2 months ago #227741 by jelo
Over the last ten years so many people asking for a way to validate email-addresses.
I cannot recommend to implement a sophisticated routine via RegEx. You will prevent someone to enter the valid email-address and still allow fake email-addresses.

Please read this:
davidcel.is/posts/stop-validating-email-addresses-with-regex/


You might export a LSS and attach it here for easier debugging.
If your question is called Q00, the subquestion check for identical input in SQ001 and SQ002 could be validated with this
((( ! is_empty(Q00_SQ001.NAOK) && (Q00_SQ001.NAOK == Q00_SQ002))))

If this works, you can expand it with your fancy RegEx.

When your Questioncode is Q00, "this.NAOK = "SQ001" translates into Q00_SQ001.NAOK = "SQ001". Which would only be true if you type "SQ001" as the email.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 2 months ago #227773 by Joffm
Hi,
I agree with @jelo about the usability of regex to check valid email addresses.

To explain more:
You have two conditions:
  1. Matching emails: this is a question condition
  2. Correct emails in each of the two entry fields: this is a subquestion condition

For the first:
In "question validation equation"
(is_empty(self.sq_SQ001.NAOK) || is_empty(self.sq_SQ002.NAOK)) && (self.sq_SQ001.NAOK == self.sq_SQ002)
and a tip

in "subquestion validation equation" (this expands to the QCode of the subquestion)
is_empty(this) or regexMatch('/^.+?@.+?\..+$/',this.NAOK)
and a tip

You may read here
[url] manual.limesurvey.org/ExpressionScript_-....22that.22_variables [/url]
[url] manual.limesurvey.org/ExpressionScript_-...code_variable_naming [/url]

Joffm

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose