amis icon indicating copy to clipboard operation
amis copied to clipboard

validations 正则表达式匹配问题

Open PengXing opened this issue 6 years ago • 2 comments

FormItem 的 validations 支持正则表达式,可以通过下面这种方式编写 validations

{
  validations: 'matchRegexp:/^(/?\w+)*$/',
  description: '格式如下:hello 或者 hello/world 或者 hello/world/everyone',
}

但是,对上面正则表达式的支持有点问题,可以看这个代码https://github.com/baidu/amis/blob/cdf3f9dd6fdc65d48e4283fe5cdf26e77bac1d16/src/utils/validations.ts#L293

由于正则表达式中包含/ 字符,匹配结果就是错误的,会导致

placeholder['__0'] = 'matchRegexp:/^(/'

拿到的正则表达式不全,所以正确正则表达式无法工作。

PengXing avatar May 14 '20 09:05 PengXing

加转义?而且你还可以用这种形式

{
  validations: {
    matchRegexp: /^(\/?\w+)*$/
  }
}

RickCole21 avatar May 14 '20 10:05 RickCole21

matchRegexp:/^(\/?\w+)*$/,加转义试过,没区别

不过下面的方式我尝试过,是 ok 的

PengXing avatar May 15 '20 03:05 PengXing