Class Validator Documentation
Decorator-based validation for TypeScript & JavaScript
class-validator uses validator.js under the hood to validate class instances with simple, composable decorators — in the browser or on Node.js.
Decorator and non-decorator based validation
Cross-platform: works in the browser and Node.js
Validates objects, arrays, and nested class instances
Custom validation classes and decorators
Dependency-injected validators via a service container
Rich set of 80+ built-in validators
Quick example
import { validate } from 'class-validator';
import { Length, Contains, IsInt, Min, Max, IsEmail } from 'class-validator';
export class Post {
@Length(10, 20)
title: string;
@Contains('hello')
text: string;
@IsInt()
@Min(0)
@Max(10)
rating: number;
@IsEmail()
email: string;
}
validate(new Post()).then(errors => {
if (errors.length > 0) console.log('validation failed', errors);
});This is an independent documentation example built by Sonicar Tech LLC and is not officially affiliated with the class-validator maintainers or TypeStack.