An open API service indexing awesome lists of open source software.

https://github.com/svtslv/class-validator-callback

ValidateCallback decorator for class-validator
https://github.com/svtslv/class-validator-callback

callback class-validator

Last synced: 8 months ago
JSON representation

ValidateCallback decorator for class-validator

Awesome Lists containing this project

README

          

# Class Validator Callback

NPM Version
Package License

## Table of Contents

- [Description](#description)
- [Installation](#installation)
- [Examples](#examples)
- [License](#license)

## Description

ValidateCallback decorator for class-validator

## Installation

```bash
npm install class-validator class-validator-callback
```

## Examples

```ts
import { validate } from 'class-validator';
import { ValidateCallback } from 'class-validator-callback';

class User {
@ValidateCallback(
(object, value) => /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/.test(value),
{ message: 'Error message for password' }
)
password: string;

@ValidateCallback(
(object, value) => object.password === value,
{ message: 'Error message for passwordConfirmation' }
)
passwordConfirmation: string;
}

const user = new User();
user.password = 'passW0rd';
user.passwordConfirmation = 'passW0rd';
validate(user).then(errors => console.log(errors));
```

## License

MIT