> For the complete documentation index, see [llms.txt](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/core-module-backend-development-with-nestjs/validation/basic-validation.md).

# Basic validation

Let's add basic rules for the incoming data.

Let's create a **module** called **common** to deal with everything not pertaining to a more specific location, such as some global enhancers.

```sh
nest g mo common
```

Inside it, in the <mark style="color:blue;">`providers`</mark> array, we can insert a global instance of the <mark style="color:blue;">`ValidationPipe`</mark>, which we'll improve soon.

```typescript
{
  provide: APP_PIPE,
  useValue: new ValidationPipe(),
}
```

With this, validation is now possible. Let's install the required dependencies to continue.

```sh
yarn add class-validator class-transformer
```

Now, remember the <mark style="color:purple;">create-user.dto</mark> file? It is a **DTO** (Data Transfer Object), in this case encapsulating the fields required to create a user. Generally, DTOs are used to hold only the essential data to do something. Hence the <mark style="color:blue;">`id`</mark> was omitted, as it is automatically generated. We will also use them to define how we want to **validate** these same fields, and it's what we'll do right now.

All of these fields are strings, so we can begin by decorating them with the <mark style="color:blue;">`@IsString()`</mark> decorator, like so:

```typescript
@IsString()
readonly name: string;
```

Now, all of them are required and must be strings. We have basic validation working. Subsequent sections will focus on several improvements to what we currently have.
