Sometimes the validation builder is not advanced enough for some of the rules you would like to build, such as checking one field against another field, or some other calculations.

When this happens the best thing to do is to make a calculated question with the validation you want - and then use that question in the Validation builder.

In this article we will walk through building an advanced validation in the designer.

Note
: The same technique can be used to Active and Read-only rules.

Advanced Validation

Assume you have the form below and you want "Number Question 2" to be valid only when it is at least 42 times larger than "Number Question 1".

Step 1 - Add calculation question for validation

Add a Calculation Question to the form, the name is not important but it can help to be descriptive, so lets call it "Number Question 2 is Valid"

Step 2 - Set Expression to be our validation

Now you need to design an expression that models our validation.

In this case, you want the calculated question's answer to be "Yes" (when true) when "Number Question 2" is 42 times bigger than "Number Question 1", else "No" (when false).

So the expression should look like:

Number_Question_2 > (42 * Number_Question_1) 

You could also use an IF statement to be more specific.

IF(Number_Question_2 > (42 * Number_Question_1), true, false) 

Step 3 - Use our calculated question in the Validation builder.

Now we just base the validation rule for "Number Question 2" off whether our calculation question is "Yes"(true) or "No"(false).

Step 4 (Optional) - Hide the calculated Question

Sometimes it can be nice for the user to see immediately whether the answer is valid as the calculation will resolve to "Yes" or "No", but in some cases you will want to hide the calculated validation question.

In these cases just tick the "Hide from user" check box in the calculated question's advanced settings.

Learn more about hiding calculated questions here.

And that's it! You can model almost any validations using calculated questions!

Useful Examples:

Validate the LENGTH of an answer

To retrieve the length of an answer, create an extra Calculated Question and set a similar expression to the following:

 LENGTH(field_you_want_to_validate) 

This Calculated Question will now display the number of characters in your field’s answer. 

Then place a Validation on your original field, so that the new Calculated Question (Length) must be the same as your desired length.

After saving, the user will be prompted to change their answer, if it isn't the correct length.

Validate if a character is a Number

If you'd like to ensure a character in an answer is a number, you can use the SUBSTRING() function to retrieve the character and an IF statement to check if it is a number. The following expression will show "valid" if the character is a number and "not valid" if it isn't, for example a letter or punctuation mark.

IF(CONTAINS("0123456789",SUBSTRING(Your_Question, Position, 1)),"valid", "not valid") 

Place a validation on your original question which checks that the new Calculated Question is showing "valid".

Validate if a character is a Letter

To check if a character is a letter, the following expression can be used in a Calculated Question. 

IF(CONTAINS("abcdefghijklmnopqrstuvwxyz",LOWERCASE(SUBSTRING(Your_Question, Position, 1))),"valid", "not valid") 

The SUBSTRING() function will find the specified character, then the LOWERCASE() function changes that character to lowercase if it is a letter. This is so that the IF statement can check if the character is one for the following letters "abcdefghijklmnopqrstuvwxyz". This will not affect the original answer if it is a capital letter.

Place a validation on your original question which checks that the new Calculated Question is showing "valid".

Note: It is possible to use multiple or combine Calculated Questions to check that an answer has valid formatting. Use "AND" or "OR" to add conditions to your Validation Rule.

Other Useful Articles:


If you have any questions or comments please send us a message at support@devicemagic.com.

Did this answer your question?