> 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/improvements-tips-module/improvements/password-validation/multiple-validations.md).

# Multiple validations

Better modularization of the password validation.

A limitation of our <mark style="color:blue;">`@IsPassword()`</mark> validator is that all the validations are being done in the same place. It would be nice to have a decorator for each individual validation. Then, the <mark style="color:blue;">`@IsPassword()`</mark> would be a composition of all of them. The main advantage of this is that it would allow for a more detailed error message, stating what specific rule was not followed. Also, parts of this validation could be used elsewhere, if necessary.

What we could do then is to create, inside <mark style="color:purple;">validators</mark>/<mark style="color:purple;">text</mark>, five different decorators, one for each rule. So, we could create the decorators:

* <mark style="color:blue;">`ContainsLowercaseLetter`</mark>
* <mark style="color:blue;">`ContainsUppercaseLetter`</mark>
* <mark style="color:blue;">`ContainsNumber`</mark>
* <mark style="color:blue;">`ContainsSpecialCharacter`</mark>
* <mark style="color:blue;">`OnlyRequiredCharacters`</mark>

So, begin by copying the contents of the <mark style="color:purple;">is-password.decorator</mark> file and pasting them in the first decorator. I'll show you the steps to be taken and you can continue by yourself with the other ones. So, after pasting the contents, perform these steps:

* Remove the JSDoc above the decorator
* Rename everything accordingly, so what is called <mark style="color:blue;">`isPassword`</mark> will become <mark style="color:blue;">`containsLowercaseLetter`</mark>, for example
* Adjust the error message to <mark style="color:blue;">`must contain at least one lowercase letter`</mark>
* Replace the regex with <mark style="color:blue;">`/.*[a-z].*/`</mark>

After finishing this, copy the result to the remaining decorators and conclude adjusting them. The <mark style="color:blue;">`OnlyRequiredCharacters`</mark> decorator has two differences:

* Its regex should be <mark style="color:blue;">`/^[a-zA-Z\d@$!%*?&]+$/`</mark>
* The message should be <mark style="color:blue;">`must contain only letters, numbers and the following special characters: @$!%*?&`</mark>

Finally, the <mark style="color:blue;">`@IsPassword()`</mark> decorator should be a combination of all of them, and also the <mark style="color:blue;">`@Length()`</mark> decorator with the required length for the password.

<mark style="color:green;">**Commit**</mark> - Separating password validation in multiple validators
