CONTAINS Function: Determine If a Field Contains an Exact Match for a Specified Character String
The CONTAINS function returns TRUE if a specified field contains an exact match for a specified character string, and returns FALSE if it does not.
The CONTAINS function can be used to determine the following conditions.
- If a specified option is selected for a "Check box" or "Multi-choice" field
- If a field in a table contains a value that exactly matches a specified character string
The evaluation of a CONTAINS function can also be used together with the IF function.
CONTAINS function syntax
CONTAINS(field_code, "search string")
Both the "field_code" and "search string" arguments need to be specified.
For the "field_code" argument, specify the field code of the field to be searched.
You can specify the following fields.
- "Check box" fields
- "Multi-choice" fields
- Fields in tables:
- "Text" fields
- "Radio button" fields
- "Drop-down" fields
- "Lookup" fields (If a field of the "string" data type is set as the Key Field)
If you set a formula with the CONTAINS function for a field in a table, the following fields can be specified as the argument.
- "Check box" fields in the same table
- "Multi-choice" fields in the same table
For the "search string" argument, specify the character string you want to search for enclosed in double quotation marks (""). If a value that exactly matches the character string specified as the "search string" is found, the function returns TRUE.
Formula examples
When specifying a field in a formula, make sure to specify the field code as the argument (and not the field name).
In the examples below, the field code is set for each field as the field name with underscores instead of spaces (e.g., the field code for the "Check box" field is "Check_box").
Formula to display "Checked" if the "Completed" checkbox is selected
The following formula displays "Checked" if the "Completed" checkbox is selected for the "Check box" field, and "Unchecked" if it is not selected.
IF(CONTAINS(Check_box, "Completed"),"Checked","Unchecked")
The formula in this example needs to be set for a "Text" field. Place a "Text" field on the app form, select Calculate automatically in the field settings, then enter the formula.
Formula to display "Working on Sundays" if the "Sunday" checkbox is selected
The following formula displays "Working on Sundays" if the "Sunday" checkbox is selected for the "Workdays" field, and "Not Working on Sundays" if it is not.
IF(CONTAINS(Workdays, "Sunday"), "Working on Sundays", "Not Working on Sundays")
The formula in this example needs to be set for a "Text" field. Place a "Text" field on the app form, select Calculate automatically in the field settings, then enter the formula.
Formula to display "Working on Weekends" if the "Saturday" or "Sunday" checkbox is selected
The following formula displays "Working on Weekends" if either the "Saturday" or "Sunday" checkbox is selected for the "Workdays" field.
The OR function is used to combine conditions.
AND, OR, and NOT Functions: Combine Conditions
IF(OR(CONTAINS(Workdays, "Saturday"),CONTAINS(Workdays, "Sunday")), "Working on Weekends", "")
The formula in this example needs to be set for a "Text" field. Place a "Text" field on the app form, select Calculate automatically in the field settings, then enter the formula.
Formula to display a different cost depending on whether a checkbox is selected
The following formula displays a different lodging cost depending on whether the checkbox in the "Lodging Option" field is selected.
If the "Breakfast Included" checkbox is selected for the "Lodging Option" field, the lodging cost is displayed as $95, which is the cost of breakfast ($15) added to the regular lodging cost ($80). If the checkbox is not selected, the lodging cost is displayed as $80.
80+IF(CONTAINS(Lodging_Option, "Breakfast Included"), 15, 0)
Formula to display "Completed" when all of a field's checkboxes are selected
The following formula displays "Completed" in the "Inspection status" field when all of the checkboxes (A, B, and C) are selected for the "Check" field.
The AND function is used to combine conditions.
AND, OR, and NOT Functions: Combine Conditions
IF(AND(CONTAINS(Check, "A"),CONTAINS(Check, "B"),CONTAINS(Check, "C")),"Completed","")
The formula in this example needs to be set for a "Text" field. Place a "Text" field on the app form, select Calculate automatically in the field settings, then enter the formula.
Formula to display "Not Completed" if not all of a field's checkboxes have been selected
The following formula displays "Not Completed" in the "Inspection status" field when any one of the checkboxes (A, B, and C) is not selected for the "Check" field.
The OR function is used to combine conditions.
AND, OR, and NOT Functions: Combine Conditions
IF(OR(CONTAINS(Check, "A"),CONTAINS(Check, "B"),CONTAINS(Check, "C")),"","Not Completed")
The formula in this example needs to be set for a "Text" field. Place a "Text" field on the app form, select Calculate automatically in the field settings, then enter the formula.
Formula to display "Urgent order" if "Urgent" is entered in a table
The following formula displays "Urgent order" in the "Order priority" field if "Urgent" is entered in the "Priority" field of a table, and "Normal" if it is not.
Formula: IF(CONTAINS(Priority, "Urgent"), "Urgent order", "Normal")
The formula in this example needs to be set for a "Text" field. Place a "Text" field on the app form, select Calculate automatically in the field settings, then enter the formula.
If a value of the "Priority" field is an exact match for the character string "Urgent", "Urgent order" is displayed.