正则表达式区分大小写不适用于 Redux-Forms

Regex Case Sensitivity Not working for Redux-Forms

我正在尝试使用 Redux-Forms 在 React/Redux 构建中进行密码验证。一切都很好,除了我似乎无法阻止密码至少包含一个大写字母。这是我的正则表达式:

^(?=[A-Z])(?=.*?[0-9])(?=.*?[^\w\s]).+$

它在正则表达式验证器和我的表单验证器中工作正常,除了大写字母外它工作正常。

const password = value =>
 value && !/^(?=[A-Z])(?=.*?[0-9])(?=.*?[^\w\s]).+$/i.test(value)
  ? 'Passwords must at least 8 characters, include one capital letter, one number, and one special character:'
  : undefined;

我们也在使用 Wizard-Form,但我没有看到其中有任何东西会扰乱这个案例。

有没有人有什么想法?

由于末尾的 /i 标志,您的正则表达式不区分大小写。 只需删除正则表达式末尾的 /i 即可使其工作:

> /^(?=[A-Z])(?=.*?[0-9])(?=.*?[^\w\s]).+$/i.test('hello1*')
true
> /^(?=[A-Z])(?=.*?[0-9])(?=.*?[^\w\s]).+$/.test('hello1*')
false