class-validator-callback
v1.0.2
Published
ValidateCallback decorator for class-validator
Downloads
434
Readme
Class Validator Callback
Table of Contents
Description
ValidateCallback decorator for class-validator
Installation
npm install class-validator class-validator-callback
Examples
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