【问题标题】:matches class-validator decorator not working for type-graphql auto validation匹配类验证器装饰器不适用于 type-graphql 自动验证
【发布时间】:2020-04-19 03:48:42
【问题描述】:

我正在尝试使用类验证器在 type-graphql 中验证我的输入类型,但 @mathes 装饰器不起作用,所有其他带有后缀“Is”的装饰器都在工作,但不是这个。

const mobileNumberRegex = /^(\+[0-9]{1,3}[- ]?)?\d{9,10}$/;

@Field()
@Matches(mobileNumberRegex)
mobileNumber!: string;

当手机号码无法使用时,我预计会出错,但它不存在。

【问题讨论】:

    标签: typescript typeorm typegraphql


    【解决方案1】:

    虽然不知道为什么 @Matches 不起作用,但您可以尝试 @IsMobilePhone(locale: string)@IsPhoneNumber(region: string) 装饰器,它们甚至可能是更优雅的解决方案

    【讨论】:

      猜你喜欢
      • 2021-06-30
      • 2021-04-04
      • 1970-01-01
      • 1970-01-01
      • 2020-08-29
      • 1970-01-01
      • 2011-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多