Email addresses

Below are two of the common validations that researchers use. For additional validation, please see Using regular expressions from the LimeSurvey Manual.

  1. Email format: Text entered follows a particular email format. 
  2. Email addresses in two fields match: Text entered in two different fields match each other 

Validating an email format

Use this validation if you'd like to check that the information entered follows the following email format:

  • allows for special characters like “ü”
  • allows when the domain name is more than 3 characters such as .tech or .company
  • only checks if "@" and "." exists within the entered email address.

Steps to validate an email format

Ensure the question type is Short free text.

  1. Add a new question or edit an existing question
  2. Under General options (right-hand side):
    1. Make sure Question type is Short free text
    2. Copy and paste the validation expression (below) into the Validation field, making sure there are no leading or trailing spaces

Validation expression: /^.+?@.+?\..+$/

email validation.jpg


Validating two email fields

Use this validation when you would like people to enter their email in two different fields in order to confirm they enter their email address correctly.

Please see the Email Validation Demonstration for an example of what this code looks like in action.


Steps to validate two email fields

NOTE: The following assumes Question code=emails (step 1) and Subquestion codes= 1& 2 (step 2). Advanced users: If you would like different codes or tips, change the highlighted areas in the code.

  1. Create a question where the Question Type is Multiple Short Text and the Question Code is emails:

code emails.png


  1. Create Subquestions where the codes are 1 & 2, respectively:

subquestions code.jpg


  1. Copy and paste the Validation expression (below) into the Question validation equation field

Validation expression: (!is_empty(emails_1.NAOK)
AND
regexMatch(‘/^.?@.?\..+$/’,emails_1.NAOK)
AND
(!is_empty(emails_2.NAOK)
or
regexMatch(‘/^.?@.?\..+$/’,emails_2.NAOK))
AND
(emails_1.NAOK ==emails_2.NAOK))

logic question validation equation.jpg


To add a validation tip

The following validation:

  • Uses the same Question and Subquestion codes as Validating two email fields
  • If the email format entered in either field does not follow the email format above, returns the message, "Please enter a valid email address."  
  • If the email addresses entered in both fields do not match, returns the message, "Email addresses do NOT match."
  • If the email addresses entered in both fields do match, returns the message, "Email addresses match."

Steps

  1. Under Question validation tip (en), in the Logic panel, enter the following validation expression:

{if(is_empty(emails_1.NAOK) or regexMatch(‘/^.+?@.+?\..+$/’,emails_1.NAOK), ”,‘Please enter a valid email address.
’)}
{if(is_empty(emails_2.NAOK) or regexMatch(‘/^.+?@.+?\..+$/’,emails_2.NAOK), ”,’Please verify the email address.
’)} {if(!is_empty(emails_1.NAOK) and !is_empty(emails_2.NAOK) and emails_1.NAOK == emails_2.NAOK, ‘Email addresses match!‘, ‘Email addresses do NOT match!‘)}

question validation tip.jpg