class-validator#matches TypeScript Examples

The following examples show how to use class-validator#matches. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: create-user.dto.ts    From nestjs-starter with MIT License 6 votes vote down vote up
@ApiProperty({
    description: 'Username for your account, must be unique.',
  })
  @IsUsernameAlreadyExist({
    message: 'Username $value already exists. Choose another username.',
  })
  @IsString()
  @MinLength(8)
  @MaxLength(20)
  @Matches(PATTERN_VALID_USERNAME, {
    message: `Username $value don't have a valid format`,
  })
  @IsNotEmpty()
  username!: string;
Example #2
Source File: update-user-dto.ts    From nestjs-starter with MIT License 6 votes vote down vote up
@ApiProperty()
  @IsUsernameAlreadyExist({ message: 'Username $value already exists. Choose another username.' })
  @IsString()
  @MinLength(8)
  @MaxLength(20)
  @Matches(PATTERN_VALID_USERNAME, {
    message: `Username $value don't have a valid format`,
  })
  @IsOptional()
  username: string;
Example #3
Source File: classes.ts    From epicgames-freegames-node with MIT License 6 votes vote down vote up
/**
   * A unique hCaptcha accessibility URL recieved in your email after signing up here: https://dashboard.hcaptcha.com/signup?type=accessibility
   * @example https://accounts.hcaptcha.com/verify_email/96e9d77b-21eb-463d-9a21-75237fb27b6c
   * @env HCAPTCHA_ACCESSIBILITY_URL
   */
  @IsOptional()
  @IsUrl()
  @Matches(
    /https:\/\/accounts\.hcaptcha\.com\/verify_email\/[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-4[0-9A-Za-z]{3}-[89ABab][0-9A-Za-z]{3}-[0-9A-Za-z]{12}/
  )
  hcaptchaAccessibilityUrl = process.env.HCAPTCHA_ACCESSIBILITY_URL;
Example #4
Source File: classes.ts    From epicgames-freegames-node with MIT License 6 votes vote down vote up
/**
   * Discord channel webhook URL.
   * Guide: https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
   * @example https://discord.com/api/webhooks/123456789123456789/A-abcdefghijklmn-abcdefghijklmnopqrst12345678-abcdefghijklmnop123456
   * @env DISCORD_WEBHOOK
   */
  @IsUrl()
  @Matches(/^.*(discord|discordapp)\.com\/api\/webhooks\/([\d]+)\/([a-zA-Z0-9_-]+)$/)
  webhookUrl: string;
Example #5
Source File: classes.ts    From epicgames-freegames-node with MIT License 6 votes vote down vote up
/**
   * If 2FA is enabled, add your TOTP secret
   * @example EMNCF83ULU3K3PXPJBSWY3DPEHPK3PXPJWY3DPEHPK3YI69R39NE
   * @env TOTP
   */
  @IsOptional()
  @Length(52)
  @Matches(/^[A-Z2-7]+=*$/) // IsBase32 also checks for mod 8 length, which these aren't
  totp?: string;
Example #6
Source File: PathI.ts    From tatum-blockchain-connector with MIT License 5 votes vote down vote up
@IsNumberString()
  @Matches(/[0-9]+/)
  public i: string;
Example #7
Source File: PublicUser.ts    From tezos-academy with MIT License 5 votes vote down vote up
@Length(2, 20)
  @Matches(/^[a-zA-Z0-9_]*$/, { message: 'Username can only contain letters, numbers and underscores' })
  username!: string
Example #8
Source File: ResetPassword.ts    From tezos-academy with MIT License 5 votes vote down vote up
@Expose()
  @Length(8, 50)
  @Matches(/^(?=.*[0-9])(?=.*[a-zA-Z])(.+)$/, { message: 'Password must have at least one letter and one digit' })
  newPassword!: string
Example #9
Source File: SignUp.ts    From tezos-academy with MIT License 5 votes vote down vote up
@Expose()
  @Length(2, 20)
  @Matches(/^[a-zA-Z0-9_]*$/, { message: 'Username can only contain letters, numbers and underscores' })
  username!: string
Example #10
Source File: SignUp.ts    From tezos-academy with MIT License 5 votes vote down vote up
@Expose()
  @Length(8, 50)
  @Matches(/^(?=.*[0-9])(?=.*[a-zA-Z])(.+)$/, { message: 'Password must have at least one letter and one digit' })
  password!: string
Example #11
Source File: User.ts    From tezos-academy with MIT License 5 votes vote down vote up
@Property({ required: true, unique: true, index: true })
  @Length(2, 20)
  @Matches(/^[a-zA-Z0-9_]*$/, { message: 'Username can only contain letters, numbers and underscores' })
  username!: string
Example #12
Source File: Pagination.ts    From tatum-blockchain-connector with MIT License 5 votes vote down vote up
@IsNumberString()
  @Matches(/[0-9]+/)
  @IsNotEmpty()
  @ValidateIf(o => o.count !== 'true')
  @IsInRange(1, 50)
  public pageSize: string;
Example #13
Source File: Pagination.ts    From tatum-blockchain-connector with MIT License 5 votes vote down vote up
@IsNumberString()
  @Matches(/[0-9]+/)
  @IsOptional()
  public offset?: string;
Example #14
Source File: PathAddressContractAddressI.ts    From tatum-blockchain-connector with MIT License 5 votes vote down vote up
@IsNumberString()
  @Matches(/[0-9]+/)
  public i: string;
Example #15
Source File: ChangePassword.ts    From tezos-academy with MIT License 5 votes vote down vote up
@Expose()
  @Length(8, 50)
  @Matches(/^(?=.*[0-9])(?=.*[a-zA-Z])(.+)$/, { message: 'Password must have at least one letter and one digit' })
  password!: string
Example #16
Source File: Pagination.ts    From tatum-blockchain-connector with MIT License 5 votes vote down vote up
@IsNumberString()
  @Matches(/[0-9]+/)
  @IsNotEmpty()
  @ValidateIf(o => o.count !== 'true')
  @IsInRange(1, 50)
  public pageSize: string;
Example #17
Source File: Pagination.ts    From tatum-blockchain-connector with MIT License 5 votes vote down vote up
@IsNumberString()
  @Matches(/[0-9]+/)
  @IsOptional()
  public offset?: string;
Example #18
Source File: Fee.ts    From tatum-blockchain-connector with MIT License 5 votes vote down vote up
@IsNotEmpty()
    @IsNumberString()
    @Matches(/^[+]?((\d+(\.\d*)?)|(\.\d+))$/)
    public gasLimit: string;
Example #19
Source File: Fee.ts    From tatum-blockchain-connector with MIT License 5 votes vote down vote up
@IsNotEmpty()
    @IsNumberString()
    @Matches(/^[+]?((\d+(\.\d*)?)|(\.\d+))$/)
    public gasPrice: string;
Example #20
Source File: PathAddressContractAddressI.ts    From tatum-blockchain-connector with MIT License 5 votes vote down vote up
@IsNumberString()
    @Matches(/[0-9]+/)
    public i: string;
Example #21
Source File: PathXpubI.ts    From tatum-blockchain-connector with MIT License 5 votes vote down vote up
@IsNumberString()
    @Matches(/[0-9]+/)
    public i: string;
Example #22
Source File: PathHeight.ts    From tatum-blockchain-connector with MIT License 5 votes vote down vote up
@IsNotEmpty()
    @IsNumberString()
    @Matches(/[0-9]+/)
    public height: string;
Example #23
Source File: trade.entities.ts    From tradingview-alerts-processor with MIT License 5 votes vote down vote up
// @IsString()
  // @IsIn(TRADING_MODES)
  // @IsOptional()
  // mode?: TradingMode;

  @IsString()
  @Matches(/.*(PERP|USD).*/)
  symbol: string;
Example #24
Source File: auth-credentials.dto.ts    From pknote-backend with GNU General Public License v3.0 5 votes vote down vote up
@ApiProperty({ description: '登录密码' })
  @IsString()
  @MinLength(6, { message: '密码长度不能小于6!' })
  @MaxLength(20, { message: '密码长度不能大于20!' })
  @Matches(/((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/, {
    message: '密码强度太低!',
  })
  readonly pwd: string;
Example #25
Source File: login-by-pwd.dto.ts    From pknote-backend with GNU General Public License v3.0 5 votes vote down vote up
@ApiProperty({ description: '登录密码' })
  @IsString()
  @MinLength(6, { message: '密码长度不能小于6!' })
  @MaxLength(20, { message: '密码长度不能大于20!' })
  @Matches(/((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/, {
    message: '密码强度太低!',
  })
  readonly pwd: string;
Example #26
Source File: ParametersValidator.ts    From affinidi-core-sdk with Apache License 2.0 5 votes vote down vote up
static validatePrimitive(schema: string, value: any) {
    let message: string
    let isValid: boolean = true

    switch (schema) {
      case did:
        isValid = matches(value, DID)
        message = `Parameter "${value}" is not a valid. Valid format: (${DID}).`
        break

      case didMethod:
        isValid = matches(value, DID_METHOD)
        message = `Parameter "${value}" is not a valid. Valid format: (${DID_METHOD}).`
        break

      case jwt:
        isValid = matches(value, JWT)
        message = `Parameter "${value}" is not a valid JWT. Valid format: (${JWT}).`
        break

      case array:
        isValid = isArray(value)
        message = `Parameter "${value}" should be an array.`
        break

      case number:
        isValid = isNumber(value)
        message = `Parameter "${value}" should be a number.`
        break

      case object:
        isValid = isObject(value)
        message = `Parameter "${value}" should be an object.`
        break

      case string:
        isValid = isString(value)
        message = `Parameter "${value}" should be a string.`
        break

      case boolean:
        isValid = isBoolean(value)
        message = `Parameter "${value}" should be a boolean.`
        break

      case isoString:
        isValid = isISO8601(value)
        message = `Parameter "${value}" is not a valid ISO 8601 date string.`
        break

      case confirmationCode:
        isValid = matches(value, COGNITO_CONFIRMATION_CODE)
        message = `Parameter "${value}" is not a valid confirmation code. Valid format: (${COGNITO_CONFIRMATION_CODE}).`
        break

      case password:
        isValid = matches(value, PASSWORD)
        message = `Parameter "${value}" is not a password. Valid format: (${PASSWORD}).`
        break
    }

    return { isValid, message }
  }
Example #27
Source File: classes.ts    From epicgames-freegames-node with MIT License 5 votes vote down vote up
/**
   * Telegram bot token obtained here: https://core.telegram.org/bots#3-how-do-i-create-a-bot
   * @example 644739147:AAGMPo-Jz3mKRnHRTnrPEDi7jUF1vqNOD5k
   * @env TELEGRAM_TOKEN
   */
  @IsString()
  @Matches(/[0-9]+:[a-zA-Z0-9_-]{35}/)
  token: string;
Example #28
Source File: create-user.request.dto.ts    From domain-driven-hexagon with MIT License 5 votes vote down vote up
@ApiProperty({ example: 'France', description: 'Country of residence' })
  @MaxLength(50)
  @MinLength(4)
  @IsString()
  @Matches(/^[a-zA-Z ]*$/)
  @Field() // <- only if you are using graphql
  readonly country: string;
Example #29
Source File: create-user.request.dto.ts    From domain-driven-hexagon with MIT License 5 votes vote down vote up
@ApiProperty({ example: 'Grande Rue', description: 'Street' })
  @MaxLength(50)
  @MinLength(5)
  @Matches(/^[a-zA-Z ]*$/)
  @Field() // <- only if you are using graphql
  readonly street: string;