How to use the class-validator.Matches 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 goldcaddy77 / warthog-starter / src / project / project.model.ts View on Github external
import { Environment } from '../environment/environment.model';
import { FeatureFlagSegment } from '../feature-flag-segment/feature-flag-segment.model';
import { FeatureFlagUser } from '../feature-flag-user/feature-flag-user.model';
import { FeatureFlag } from '../feature-flag/feature-flag.model';
import { Segment } from '../segment/segment.model';
import { UserSegment } from '../user-segment/user-segment.model';

import { Matches } from 'class-validator';

@Model()
export class Project extends BaseModel {
  @StringField({ maxLength: 50, minLength: 3, nullable: false })
  name!: string;

  @Matches(/^[a-z0-9]+(-[a-z0-9]+)*$/) // Lowercase sluggified string
  @StringField({ maxLength: 20, minLength: 3, nullable: false, unique: true })
  key!: string;

  @OneToMany(() => Environment, (environment: Environment) => environment.project)
  environments?: Environment[];

  @OneToMany(() => Segment, (segment: Segment) => segment.project)
  segments?: Segment[];

  @OneToMany(() => FeatureFlag, (featureFlag: FeatureFlag) => featureFlag.project)
  featureFlags?: FeatureFlag[];

  @OneToMany(() => FeatureFlagUser, (featureFlagUser: FeatureFlagUser) => featureFlagUser.project)
  featureFlagUsers?: FeatureFlagUser[];

  @OneToMany(
github ahmetuysal / nest-hackathon-starter / src / contract / request / signup-request.model.ts View on Github external
@ApiModelProperty()
  @IsNotEmpty()
  // alphanumeric characters and - are valid
  // you can change this as you like
  @Matches(RegExp('^[a-zA-Z0-9\\-]+$'))
  @MaxLength(20)
  username: string;

  @ApiModelProperty()
  @IsNotEmpty()
  @MinLength(8)
  password: string;

  @ApiModelProperty()
  @IsNotEmpty()
  @Matches(RegExp('^[A-Za-zıöüçğşİÖÜÇĞŞñÑáéíóúÁÉÍÓÚ ]+$'))
  @MaxLength(20)
  firstName: string;

  @ApiModelProperty()
  @IsNotEmpty()
  @Matches(RegExp('^[A-Za-zıöüçğşİÖÜÇĞŞñÑáéíóúÁÉÍÓÚ ]+$'))
  @MaxLength(20)
  lastName: string;

  @ApiModelProperty()
  @IsOptional()
  @IsNotEmpty()
  @Matches(RegExp('^[A-Za-zıöüçğşİÖÜÇĞŞñÑáéíóúÁÉÍÓÚ ]+$'))
  @MaxLength(20)
  middleName?: string;
}
github xmlking / ngx-starter-kit / apps / api / src / app / project / dto / find-projects.dto.ts View on Github external
readonly createdBy?: User;

  @IsOptional()
  @IsString()
  readonly clusterName?: string;

  @IsOptional()
  @ArrayUnique()
  @IsString({ each: true })
  @Transform(value => (value ? value.split(',') : []))
  readonly groups?: string[];

  @IsOptional()
  @IsAscii()
  @Length(5, 100)
  @Matches(/^[a-z\d-]+$/)
  readonly namespace?: string;

  @IsOptional()
  @IsAscii()
  @Length(5, 100)
  @Matches(/^[a-z\d-]+$/)
  readonly serviceAccountName?: string;

  @IsOptional()
  @ValidateNested()
  @Type(() => Labels)
  readonly labels?: Labels;

  @Transform((val: string) => val === 'true')
  @IsOptional()
  @IsBoolean()
github xmlking / ngx-starter-kit / apps / api / src / app / project / dto / create-project.dto.ts View on Github external
@IsString()
  @Matches(/^[a-zA-Z0-9\d-]+$/)
  readonly name: string;

  @IsOptional()
  @IsString()
  readonly description?: string;

  @IsString()
  @IsNotEmpty()
  readonly clusterName: string;

  @IsAscii()
  @IsNotEmpty()
  @Length(5, 100)
  @Matches(/^[a-z\d-]+$/)
  @IsNamespaceUnique()
  readonly namespace: string;

  @IsAscii()
  @IsNotEmpty()
  @Length(5, 100)
  @Matches(/^[a-z\d-]+$/)
  readonly serviceAccountName: string;

  @IsOptional()
  @IsString()
  username?: string;

  @IsOptional()
  @IsString()
  @IsEmail()
github Kibibit / achievibit / src / config / achievibit-config.model.ts View on Github external
nodeEnv = 'development';

  @Expose()
  @IsNumber()
  port = 10101;

  @Expose()
  @IsOptional()
  @IsString()
  @IsUrl({ protocols: [ 'mongodb', 'mongodb+srv' ], require_tld: false }, {
    message: '$property should be a valid mongodb URL'
  })
  dbUrl: string;

  @Expose()
  @Matches(SMEE_IO_REGEX)
  @IsUrl()
  webhookProxyUrl = `https://smee.io/achievibit-${ uuidv1() }`;

  @Expose()
  @Matches(ENDPONT_PATH_REGEX, null, {
    message: 'should be a server endpoint path matching the regex: $constraint1'
  })
  @Transform((url) => trim(url, '/'))
  webhookDestinationUrl = 'events';

  @IsBoolean()
  saveToFile = false;

  constructor(partial: Partial = {}) {
    Object.assign(this, partial);
  }
github NationalBankBelgium / stark / packages / stark-core / src / configuration / entities / application / app-config.entity.ts View on Github external
@IsString({ groups: ["logging"] })
	@autoserialize
	public loggingCorrelationIdHttpHeaderName: string;

	@IsDefined({ groups: ["temp"] })
	@IsBoolean({ groups: ["temp"] })
	@autoserialize
	public routerLoggingEnabled!: boolean;

	@IsBoolean({ groups: ["temp"] })
	@autoserialize
	public routerVisualizerEnabled: boolean;

	@IsNotEmpty({ groups: ["settings"] })
	@IsString({ groups: ["settings"] })
	@Matches(/^[a-z]{2}$/, { groups: ["settings"] })
	@autoserialize
	public defaultLanguage!: string;

	@IsDefined({ groups: ["session"] })
	@IsPositive({ groups: ["session"] })
	@autoserialize
	public sessionTimeout: number;

	@IsPositive({ groups: ["session"] })
	@autoserialize
	public sessionTimeoutWarningPeriod: number;

	@ValidateIf(StarkApplicationConfigImpl.validateIfKeepAliveEnabled, { groups: ["session"] })
	@IsPositive({ groups: ["session"] })
	@autoserialize
	public keepAliveInterval?: number;
github Kibibit / achievibit / src / config / achievibit-config.model.ts View on Github external
@Expose()
  @IsOptional()
  @IsString()
  @IsUrl({ protocols: [ 'mongodb', 'mongodb+srv' ], require_tld: false }, {
    message: '$property should be a valid mongodb URL'
  })
  dbUrl: string;

  @Expose()
  @Matches(SMEE_IO_REGEX)
  @IsUrl()
  webhookProxyUrl = `https://smee.io/achievibit-${ uuidv1() }`;

  @Expose()
  @Matches(ENDPONT_PATH_REGEX, null, {
    message: 'should be a server endpoint path matching the regex: $constraint1'
  })
  @Transform((url) => trim(url, '/'))
  webhookDestinationUrl = 'events';

  @IsBoolean()
  saveToFile = false;

  constructor(partial: Partial = {}) {
    Object.assign(this, partial);
  }
}
github backstopmedia / nest-book-example / src / modules / user / requests / create-user.request.ts View on Github external
IsNotEmpty,
    IsDefined,
    IsString,
    Length,
    Matches
} from 'class-validator';

export class CreateUserRequest {
    @IsEmail()
    @IsNotEmpty()
    @IsDefined()
    @IsString()
    public email: string;

    @Length(8)
    @Matches(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)\S+$/)
    @IsDefined()
    @IsString()
    public password: string;

    @IsNotEmpty()
    @IsDefined()
    @IsString()
    public firstName: string;

    @IsNotEmpty()
    @IsDefined()
    @IsString()
    public lastName: string;
}
github jiayisheji / nest-cnode / src / feature / auth / dto / register.dto.ts View on Github external
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: '确认密码不能为空',
    })
    @IsEqualsThan('pass', {
        message: '两次密码输入不一致。',
github backstopmedia / nest-book-example / src / modules / user / requests / update-user.request.ts View on Github external
Length,
    Matches,
    IsDate,
    IsOptional
} from 'class-validator';
import { ApiModelPropertyOptional } from '@nestjs/swagger';

export class UpdateUserRequest {
    @IsEmail()
    @IsOptional()
    @IsString()
    @ApiModelPropertyOptional()
    public email: string;

    @Length(8)
    @Matches(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)\S+$/)
    @IsOptional()
    @IsString()
    @ApiModelPropertyOptional()
    public password: string;

    @IsNotEmpty()
    @IsOptional()
    @IsString()
    @ApiModelPropertyOptional()
    public firstName: string;

    @IsNotEmpty()
    @IsOptional()
    @IsString()
    @ApiModelPropertyOptional()
    public lastName: string;