> 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/form-management/form-designer/answers/answer-properties/entry-validation.md).

# Entry Validation

## ☑️ What entry validation ?

Beside checking if a value has been entered in a field you may also setup more advanced rules using regular expression to make sure that the text entered by the respondent matches certain conditions.

You may also set the **maximum length of characters** allowed to be entered in your field.

![](/files/-MBxSXjb6_rt4xDgQCuU)

{% hint style="info" %}
Advanced users may also create a custom field based [answer type](/form-management/form-designer/answers/answer-types/creating-new-type.md) using  [custom javascript validation](/form-management/form-designer/answers/answer-types/creating-new-type/custom-validation-code.md) to validate the respondent entries.
{% endhint %}

## 🔢 Regular expressions

A [regular expression](https://en.wikipedia.org/wiki/Regular_expression) (regex) is a string based search pattern that will check that the text entered by the respondent matches the expression pattern or not.&#x20;

![](/files/-MBhF_WSjl4w9Zy_E3R9)

Using these patterns you check a value using patterns like emails, numbers, zip codes etc ... Almost any [field](/form-management/form-designer/answers/answer-types/entry-field.md) based type can be validated against a regular expression created using the regular expression editor.

## ➕ Adding a regular expressions

To add a regular expression go to the [answer properties](/form-management/form-designer/answers/answer-properties.md) page and click on the **+** icon

![](/files/-MBxmVt6uM9ItWMtBWkC)

{% hint style="info" %}
Regular expressions are only available to the user who created them. If you would like to share your regular expression with all the other ngSurvey users you may turn on its **built-in** property.
{% endhint %}

## 🔅 Regular expression properties

* **`Name`** is the display name of the regular expression.
* **`Regular expression`** is the actual regular expression pattern that will be used to match the respondent answer .
* **`Error message`** error message that will be shown to the respondent if its entry doesn't match the pattern.
* **`Built in`** let us share the regular expression with all the other users.

{% hint style="info" %}
You may find pre-made regular expression and test yours at  <https://regex101.com/>
{% endhint %}

## 🔢 Javascript

For field based answers you can set the Javascript validation and Validation message property on the [answer properties](/form-management/form-designer/answers/answer-properties/field-properties.md) to use custom javascript code to validate your answer. \
\
In the code below respondentAnswerValue will be replaced by the actual value of the field. If the code returns false ngSurvey will block the submit or navigation and show the validation message.

```
return (respondentAnswerValue >= 18 && respondentAnswerValue <= 99);
```

In the code below we are using the getAnswer in the validation context to get a value from another answer in the survey. Here we are looking up an answer with a reporting alias set to "hh\_people".&#x20;

<pre><code><a data-footnote-ref href="#user-content-fn-1">re</a>turn (respondentAnswerValue &#x3C;= validationContext.getAnswer('hh_people'));
</code></pre>

The validation context support following method and properties

```typescript
export class ValidationContext {
   answer:Answer, // Current answer being validated
   question:Question, // Current question of the answer being validated
   questions:Question[], // All survey questions
   answers: Answer[];  // All survey answers

  public getAnswer(id: string): string // Get the value of an answer by looking up its reporting alias or id
  public isSelectedAnswer(id: string, value: string): boolean // Look up a question based on its id or reporting alias and check if the given value is being selected 
}

```

[^1]:


---

# 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:

```
GET https://docs.ngsurvey.com/form-management/form-designer/answers/answer-properties/entry-validation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
