> For the complete documentation index, see [llms.txt](https://book.restfulnode.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.restfulnode.com/part-2/chapter-5/4-validation.md).

# Validation

**Validation** is the act of determining if the input data is in proper form. There are two types of validation, **form validation** and **service validation**.

## Form Validation

**Form validation** is simply how one would validate the data if it were a form from the frontend.

Below are some common examples of what would be considered form validation of a user registration endpoint you might build.

* Email
  * Required.
  * Correct email format.
* Password
  * At least 6 characters in length.
  * Must contain 1 number.
  * Must contain 1 alphabetical character.
* Invite\_Code
  * A 10 digit number.

Notice how these are quite generic and simple, because these do not pertain to any specific business rules.

## Service Validation

**Service validation** is any type of validation that involves the business logic of your application.

Suppose we use the same user registration endpoint example from above, except this time we have specific business logic that needs validation.

* Email
  * Must not be taken already.
* Invite\_Code
  * Must be a valid 10 digit number, where only users who have been sent email with that code can have a truly valid one.

Notice these constraints are put in the specification of the application and are not generic at all.

## Sanitization

In addition to validation, there is also the sanitization of data. **Sanitization** is the act of removing and/or replacing any illegal or unwanted characters from the data. It goes hand in hand with validation because sanitizing data before and/or after the validation of data allows us to pass that data with more confidence throughout our application.

Here are some common examples:

1. Trimming out spaces.
2. Converting characters to HTML entities.
3. Escape strings.
4. Getting rid of special characters.
5. Converting strings to only lower cases.


---

# 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://book.restfulnode.com/part-2/chapter-5/4-validation.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.
