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
- Host: GitHub
- URL: https://github.com/svtslv/class-validator-callback
- Owner: svtslv
- Created: 2020-03-19T10:13:53.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-18T01:17:04.000Z (almost 2 years ago)
- Last Synced: 2025-08-27T11:47:57.835Z (8 months ago)
- Topics: callback, class-validator
- Language: TypeScript
- Size: 843 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Class Validator Callback
## 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