我尝试使用类验证器在type-graphql中验证我的输入类型,但@mathes装饰器不起作用,所有其他带有' is‘后缀的装饰器都在工作,但这个不起作用。
const mobileNumberRegex = /^(\+[0-9]{1,3}[- ]?)?\d{9,10}$/;
@Field()
@Matches(mobileNumberRegex)
mobileNumber!: string;我期待着当手机号码不工作时出现错误,但它不在那里。
发布于 2020-01-30 22:07:01
虽然不知道为什么@Matches不能工作,但是您可以尝试一下@IsMobilePhone(locale: string)和@IsPhoneNumber(region: string)装饰器,这可能是一个更优雅的解决方案
https://stackoverflow.com/questions/59530140
复制相似问题