> For the complete documentation index, see [llms.txt](https://docs.ngsurvey.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ngsurvey.com/projects/import-export/xlsform/survey-sheet/constraint.md).

# Constraint

The constraint column is used to validate user input. It prevents the user from continuing until the answer meets a condition you define.

If the answer doesn't satisfy the constraint, a message defined in `constraint_message` is shown to the user.

## 📝 How constraints work

The value of the question is represented by a dot (`.`), which means “the current answer.” You build a logic expression using that value.

Constraints are commonly used to:

* Set numeric ranges (e.g., age must be between 0 and 120)
* Require matching formats (e.g., ZIP codes, emails)
* Enforce dependencies (e.g., end date after start date)

| type    | name  | label         | constraint                         | constraint\_message           |
| ------- | ----- | ------------- | ---------------------------------- | ----------------------------- |
| integer | age   | Your age      | . >= 18 and . <= 99                | Age must be between 18 and 99 |
| text    | zip   | ZIP code      | regex(., '^\d{5}$')                | Enter a 5-digit ZIP code      |
| text    | email | Email address | regex(., '^\[^@]+@\[^@]+.\[^@]+$') | Enter a valid email           |
| date    | end   | End date      | . >= ${start}                      | End date must be after start  |

## ☑️ Using the dot (.) in constraint

The dot `.` represents the value entered by the user for the current question. Use it inside functions and expressions:

* `. >= 0` — valid if value is 0 or higher
* `regex(., '^\d{5}$')` — valid if it matches the pattern

## 🔠 Variable references

You can use `${question_name}` to reference answers from other questions in the form. Make sure referenced questions appear earlier in the form.

Example:

* `. > ${min_age}` — ensures current input is greater than a previously entered value

## 🔢 Operators and functions for constraints

Same as relevance, you can use:

\=, !=, >, <, >=, <= and, or, not()

| Function        | Description                          | Example                                |
| --------------- | ------------------------------------ | -------------------------------------- |
| regex()         | Validates the format of a text input | `regex(., '^\d{5}$')` for US ZIP codes |
| string-length() | Checks the number of characters      | `string-length(.) <= 50`               |
| selected()      | Checks if a choice was selected      | `selected(${choices}, 'option1')`      |
| today()         | Gets the current date                | `. <= today()`                         |
| now()           | Gets current date and time           | `. <= now()`                           |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ngsurvey.com/projects/import-export/xlsform/survey-sheet/constraint.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
