Skip to content

svtslv/class-validator-callback

Repository files navigation

Class Validator Callback

NPM Version Package License

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

About

ValidateCallback decorator for class-validator

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published