How to use the class-validator.MinLength function in class-validator

To help you get started, we’ve selected a few class-validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ZhiXiao-Lin / nestify / server / src / common / dtos / login.dto.ts View on Github external
import { IsMobilePhone, MinLength, MaxLength, IsNotEmpty } from 'class-validator';
import { ApiModelProperty } from '@nestjs/swagger';

export class LoginDto {
	@ApiModelProperty()
	// @IsMobilePhone('zh-CN', {
	// 	message: '手机号无效'
	// })
	@IsNotEmpty({
		message: '帐号不能为空'
	})
	readonly account: string;

	@ApiModelProperty()
	@MinLength(8, {
		message: '密码不能少于8位'
	})
	@MaxLength(12, {
		message: '密码不能大于12位'
	})
	@IsNotEmpty({
		message: '密码不能为空'
	})
	readonly password: string;
}
github xmlking / ngx-starter-kit / apps / api / src / app / project / cluster / dto / create-cluster.dto.ts View on Github external
export class CreateClusterDto {
  @IsNotEmpty()
  @IsAscii()
  @MinLength(3)
  @MaxLength(15)
  name: string;

  @IsNotEmpty()
  @MinLength(3)
  @MaxLength(6)
  ver: string;

  @IsNotEmpty()
  @IsUrl({ require_tld: false })
  @MinLength(10)
  @MaxLength(256)
  baseUrl: string;

  @IsNotEmpty()
  @IsString()
  @MinLength(256)
  token: string;
}
github jiayisheji / nest-cnode / src / feature / auth / dto / register.dto.ts View on Github external
render: ViewsPath.Register,
    locals: {
        loginname: true,
        pass: false,
        re_pass: false,
        email: true,
    },
    priority: {
        loginname: ['MinLength', 'Matches'],
        pass: ['IsNotEmpty', 'IsByteLength'],
        re_pass: ['IsNotEmpty', 'IsEqualsThan'],
        email: ['IsNotEmpty', 'IsEmail'],
    },
})
export class RegisterDto {
    @MinLength(5, {
        message: '用户名至少需要5个字符',
    })
    @Matches(/^[a-zA-Z0-9\-_]\w{4,20}$/, {
        message: '用户名不合法',
    })
    @Transform(value => value.toLowerCase(), { toClassOnly: true })
    readonly loginname: string;
    @IsNotEmpty({
        message: '密码不能为空',
    })
    @IsByteLength(6, 18, {
        message: '密码长度不是6-18位',
    })
    readonly pass: string;
    @IsNotEmpty({
        message: '确认密码不能为空',
github goparrot / geocoder / src / model / geocode-query.ts View on Github external
import { IsNotEmpty, IsNumber, IsOptional, IsString, Max, MaxLength, Min, MinLength } from 'class-validator';
import { GeocodeQueryInterface } from '../interface';
import { ToBoolean } from '../util/transformer';
import { IsExactMatchApplicable } from '../validation';
import { Query } from './query';

export class GeocodeQuery extends Query implements GeocodeQueryInterface {
    @IsString()
    @IsNotEmpty()
    @MinLength(5)
    @MaxLength(150)
    address: string;

    @ToBoolean()
    @IsExactMatchApplicable()
    exactMatch: boolean = false;

    @IsOptional()
    @IsString()
    @MinLength(2)
    @MaxLength(100)
    country?: string;

    @IsOptional()
    @IsString()
    @MinLength(2)
github danielwii / asuna-node-server / src / modules / core / auth / auth.dto.ts View on Github external
export class ResetPasswordDto {
  @ApiProperty({ type: 'username' })
  @IsString()
  @Transform(value => _.trim(value))
  readonly username: string;

  @ApiProperty({ type: 'email' })
  @IsEmail()
  @Transform(value => (value ? _.trim(value) : null))
  @IsOptional()
  readonly email?: string;

  @ApiProperty({ minLength: 6 })
  @IsNotEmpty()
  @MinLength(6)
  readonly password: string;
}

/**
 * for admin auth currently
 */
export class SignDto {
  @ApiProperty({ type: 'email' })
  @IsString()
  @Transform(value => _.trim(value))
  @IsNotEmpty()
  readonly email: string;

  @ApiProperty()
  @IsNotEmpty()
  readonly password: string;
github vellengs / nestx / packages / server / src / auth / dto / Register.dto.ts View on Github external
import { IsNotEmpty, IsString, MinLength, Length, IsEmail, IsOptional } from 'class-validator';

export class RegisterReq {
    @IsNotEmpty()
    @MinLength(5)
    @IsString()
    username: string;

    @IsNotEmpty()
    @MinLength(5)
    @IsString()
    password: string;

    @IsNotEmpty()
    @MinLength(11)
    @IsString()
    mobile: string;

    @Length(5, 50)
    @IsString()
    @IsEmail()
    email: string;

    name?: string;

    @Length(2, 5)
github jmcdo29 / zeldaPlay / apps / api / src / app / auth / auth / models / signup.graphql.ts View on Github external
@IsEmail()
  @IsString()
  @IsNotEmpty()
  @Field()
  email!: string;

  @IsString()
  @MinLength(8)
  @IsNotEmpty()
  @IsPassword()
  @Field()
  password!: string;

  @IsNotEmpty()
  @IsString()
  @MinLength(8)
  @IsPassword()
  @Field()
  confirmationPassword!: string;

  @IsString()
  @IsNotEmpty()
  @Field()
  firstName!: string;

  @IsString()
  @IsNotEmpty()
  @Field()
  lastName!: string;

  @IsBoolean()
  @IsOptional()
github goparrot / geocoder / src / util / world-country / world-country-query.ts View on Github external
@MinLength(2)
    @MaxLength(2)
    @Transform((v: string) =>
        v
            ? v
                  .toString()
                  .trim()
                  .toUpperCase()
            : undefined,
    )
    @Expose()
    cca2?: string;

    @IsOptional()
    @IsString()
    @MinLength(3)
    @MaxLength(3)
    @Transform((v: string) =>
        v
            ? v
                  .toString()
                  .trim()
                  .toUpperCase()
            : undefined,
    )
    @Expose()
    cca3?: string;

    @IsOptional()
    @IsInt()
    @IsNumberString()
    @MinLength(3)
github xmlking / ngx-starter-kit / apps / api / src / app / project / cluster / dto / create-cluster.dto.ts View on Github external
name: string;

  @IsNotEmpty()
  @MinLength(3)
  @MaxLength(6)
  ver: string;

  @IsNotEmpty()
  @IsUrl({ require_tld: false })
  @MinLength(10)
  @MaxLength(256)
  baseUrl: string;

  @IsNotEmpty()
  @IsString()
  @MinLength(256)
  token: string;
}
github vellengs / nestx / packages / server / dist / auth / dto / login.dto.js View on Github external
Object.defineProperty(exports, "__esModule", { value: true });
const class_validator_1 = require("class-validator");
class LoginReq {
}
__decorate([
    class_validator_1.IsNotEmpty(),
    class_validator_1.IsString(),
    __metadata("design:type", String)
], LoginReq.prototype, "username", void 0);
__decorate([
    class_validator_1.IsOptional(),
    __metadata("design:type", String)
], LoginReq.prototype, "type", void 0);
__decorate([
    class_validator_1.IsNotEmpty(),
    class_validator_1.MinLength(5, {
        message: 'Your password is too short! It must be 5 characters or more!',
    }),
    __metadata("design:type", String)
], LoginReq.prototype, "password", void 0);
exports.LoginReq = LoginReq;
class LoginRes {
}
exports.LoginRes = LoginRes;
//# sourceMappingURL=login.dto.js.map