ValidatorConstraintInterface,
} from "class-validator";
@ValidatorConstraint({ name: "RutValidator", async: false })
class RutValidator implements ValidatorConstraintInterface {
validate(value: string): boolean {
if (!value || !value.match(/^[0-9]+[-]{1}[0-9kK]{1}$/)) {
defaultMessage(): string {
return `$property must be a valid RUT (e.g. 12345678-9)`;
export function IsRut(validationOptions?: ValidationOptions) {
return (object: unknown, propertyName: string) => {
target: object.constructor,
propertyName: propertyName,
options: validationOptions,