Skip to main content

Kinesis Support

All the topics, resources needed for Kinesis.


FocusVision Knowledge Base

Response Validation

Validation conditions are used to program for situations in which you wish to stop the respondent from proceeding based on their current provided responses. If a validation is triggered it will flag the question and display the corresponding error message. For tables, the particular part of the table with the error will be highlighted and hovering over the area will display the error message. Some validations are automatically checked based on the question properties. For example, if a "min value" is supplied within a number question's properties. These built-in error messages can be customized in your project's Survey Properties.

1:  Validation Programming

To program any custom validation, look for the  icon next to each question or table within the Survey Editor.

This particular question has two validation statements programmed on it already. Any single question can have an unlimited number of validation statements programmed.

To add new validation, click on the button at the bottom and the following screen will appear:

Use the Condition Editor to create your logic, and type the error message that you wish respondents to see in the input where specified. Click the check mark to save your validation.

2:  Email Validation

Email questions must be set up as Text Questions for this to work.

!preg_match(",[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?,", $QEMAIL)

3:  Zip / Postal Code Validation

Best to implement zip code question as text to allow leading zeros to be stored (if programmed as a Number Question, the system will export 07030 as 7030, which is not ideal).

US Format, 5-digit (ex. 12345):

!preg_match('/^\d{5}$/', $Qzip)

US Format, 5-digit + Optional 4 Digit Extension (ex. 12345 or 12345-1234)

!preg_match('/^\d{5}(-\d{4})?$/', $Qzip)

Canadian Portal Codes (ex. A0A0A0, A0A 0A0) Canadian zip codes must follow the format of 'A0A0A0' OR 'A0A 0A0' where 'A' is any letter except D, F, I, O, Q, or U and '0' is any number 0-9.

((strlen($Qpost)==6 AND !(preg_match('/[ABCEGHJKLMNPRSTVWXYZabceghjklmnprstvwxyz][0-9][ABCEGHJKLMNPRSTVWXYZabceghjklmnprstvwxyz][0-9][ABCEGHJKLMNPRSTVWXYZabceghjklmnprstvwxyz][0-9]/',$Qpost))) OR
(strlen($Qpost)==7 AND !(preg_match('/[ABCEGHJKLMNPRSTVWXYZabceghjklmnprstvwxyz][0-9][ABCEGHJKLMNPRSTVWXYZabceghjklmnprstvwxyz][" "][0-9][ABCEGHJKLMNPRSTVWXYZabceghjklmnprstvwxyz][0-9]/',$Qpost))) OR
(strlen($Qpost)!=6 AND strlen($Qpost)!=7))

UK Postcodes + Optional Space in Formatting (ex. EC1A 1BB, M1 1AA)

!preg_match('/^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$/', $Qpost)

4:  Non-Integer Validation

Returns error if answer is NON-INTEGER (contains a decimal). This is helpful if you'd like to prevent the rounding that occurs upon submitting numeric question types.

NOTE: You will have to change "$Qint" to match your question label.

!preg_match('/(?<!\S)\d++(?!\S)/', $Qint)

5:  Ranking Question with Other Field Validation

Checks to see if the "other specify" option is ranked and the Other specify field is empty, assuming that the other option is option number 11.

in_array(11,$QRANK) AND $QRANKo1==""

Checks to see if the "other specify" option is NOT ranked and the Other specify field is NOT empty.

!(in_array(11,$QRANK)) AND $QRANKo1!=""

Return to top

6:  "Don't Know" Opt-Out Checkbox Validation

View Demo

The first thing you will need to do is create your question, then a checkbox question, which will be used for our Don't Know option. From there, be sure to delete the ~QTEXT~ from the surrounding HTML of the Don't Know checkbox question. Now, we will need to insert the custom validations -- the first one should go on your question, and the second should go on the Don't Know checkbox. In the demo above I used a Number question with our Don't Know, so the validation will be as follows (be sure to replace the Qlabels with your labels):

Validation and Error message for Question:

$Q1=="" AND $Q1DK[1]==0
Your answer is required.

Validation for Don't Know Checkbox:

$Q1!="" AND $Q1DK[1]==1
Your answer is only required if you did not answer above.

Please be sure to mark both the questions as Not Required -- the validations will take care of that. Also, only apply a page break to the Don't Know checkbox question.

7:  Current Date Check Validation

#The date question type stores data in the YYYY-MM-DD format, regardless of the input mask:
strtotime($Qdate[0] . '-' . $Qdate[1] . '-' . $Qdate[2]) > time()

#For separate DAY, MONTH and YEAR numeric or pulldown questions:
strtotime($Qyear.'/'.$Qmonth.'/'.'$Qday) > time()

8:  Simpler Email Validation

The following expression can be used to "validate" an email address in Kinesis (by displaying a "non-conformance" message):

 (preg_match("/^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$/i", $Qemail) == 0) OR (preg_match("/^\.|\.@|@-|-\.[a-z]{2,4}$/i", $Qemail) == 1)

9:  Constant Sum / Add to Total Validation

It is common to need a number matrix table to equal exactly 100 (or any other number for that matter). In order for this to work, you will need to go into your matrix table and click on "Edit table validation". From there, you will need to edit the row validation by adding every row and checking to see if it does not equal 100. For example, if my table contained the questions $Q1a through $Q1d, the logic would look like this:

 $Q1a +  $Q1b +  $Q1c +  $Q1d != 100

The != stands for "does not equal", so if Q1a + Q1b + Q1c + Q1d does not equal 100 the error message that you specify will be shown to the respondent.

10:  Validate a URL

The following syntax allows you to parse a URL entered into a text or textarea question to determine if it's properly formed.

  • Was this article helpful?