[英]Getting "compiled with warnings" for using regular expression
我正在编译警告警报。 这就是信息。
Compiled with warnings
。
./src/components/register/register.js
Line 5: Unnecessary escape character: \$ no-useless-escape
Line 5: Unnecessary escape character: \^ no-useless-escape
Line 5: Unnecessary escape character: \* no-useless-escape
这是第 5 行的代码。我用它来检查密码是否包含 1 个大写字母、1 个小写字母、1 个数字、1 个特殊字符以及是否超过 8 个字符。
const passwordRegex = RegExp(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})/);
我想知道为什么我会收到此警报? 我该如何让它消失?
警告指出 - 正确 - 字符$
、 ^
和*
不需要在字符类[!@#$%^&*]
进行转义。 在此上下文中唯一具有特殊含义的字符是[
、 ]
、 -
和\\
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.