Basic Validation Conditions

Validation Conditions "check" responses to make sure they meet the constraints that you specify. Validation conditions work such that if the entered information does not meet the logic you specify, a flagged message pops up for the user and blocks them from proceeding to the next question.

  • For a basic validation condition you can use the Expression Builder, which is described in the Beginner Tutorial

  • Whenever you are referring to the value of the question to which you are adding the validation condition, you will see the question referred to as "."

  • Common components of a validation condition might be the use of = , >, and <. For example:

    • . > 8 (the response must be greater than 8)

    • . =! 0 (the response cannot be 0)

    • . > 1 and . < 10 (the response must be greater than 1 and also less than 10) 

  • Restricting the length of a numeric ID or text field you can use the function string-length() (for more information on functions see CommCare Functions)

    • To require a specific length (example: 8 characters long): string-length(.) = 8. NOTE: This length count includes spaces. 

    • To restrict the length of a string to a range of characters (example: 7-9 characters long): string-length(.) >=7 and string-length(.) <=9

  • To validate a date relative to today's date you can use the function today():

    • Restrict a date entered so that it cannot be in the future (must be today or earlier): . <= today()

    • Restrict a date such that it must be within the previous 10 months (305 days): . > today() - 305 and . <= today()

  • To require the user to enter in a text entry question in a specific format, you can use various regex functions. 

    • Requires the first letter be capitalized, and all other letters be lowercase: regex(., "^[A-Z][a-z]+$")

If you want to create complex expressions please see Advanced Validation Conditions.

Validation Message

In the Validation Message field, enter the desired message that will pop up if the entered information does not meet your validation condition.  You can enter a different message for each language of your application.  If you do not specify a validation message the user will see a generic message like "The response is out of range." It is strongly recommended to always use a useful validation message.

Examples

Icon

This Validation makes sure that the phone number entered contains 10 digits.

Complex Example

Icon

This Validation makes sure that the date of birth is both in the past, and between the ages of 10 and 59.