javascript - Unnecessary escape character warning when running 'npm start' with React app
问题描述
I'm running my React app with npm start and App compiles but i'm getting this warning in terminal:
Line 24: Unnecessary escape character: \[ no-useless-escape
Here's the code it's referring to:
validateEmail(email) {
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
How do I address this warning?
解决方案
You need to add another slash /
into your code like this
function validateEmail(email) {
const re = /^(([^<>()\\[\]\\.,;:\s@"]+(\.[^<>()\\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
推荐阅读
- database - 如何使用 Katalon Studio 自定义关键字
- spring - Keycloak Spring 多租户空指针异常
- python - R 相当于 scipy.integrate.simps()?
- tfs - 服务挂钩消息卡在队列或处理状态
- regex - 扩展 Cucumber 步骤
- python - 如何知道用户是否在 Pyrebase 和 Flask 中登录?
- ibm-cloud - IBM Unica Campaign 外部 CSV 文件导入
- debugging - 通过意图启动时,如何在 Android 中调试我的 Xamarin 应用程序?
- wpf - 如果将列宽设置为“2 *”以在 xaml WPF 中绑定?
- swift - 将音频切换到扬声器不会保留