问题描述
限时送ChatGPT账号..我按照 https://vuejs/v2/中提供的方法尝试了此代码食谱/form-validation.html.
validEmail: function (email) {
var 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);
}
Vuejs 是说 - error: Unnecessary escape character: \[ (no-useless-escape) at src/components/form.vue:125:65
这是行 varre = ...
Vuejs is saying that - error: Unnecessary escape character: \[ (no-useless-escape) at src/components/form.vue:125:65
which is the line var re = ...
我在这里做错了什么?我把这个函数称为 this.validEmail(this.modelname)
What I am getting wrong here? I called this function like this.validEmail(this.modelname)
推荐答案
错误"(从技术上讲它只是一个警告)是说您不需要在正则表达式中转义 [
位于字符集内([]
语法),因为它的含义是明确的(您不能创建嵌套字符集);]
,另一方面,确实需要转义,因为它将被解释为结束字符集的正则表达式语法的一部分而不是文字 ]
字符.
The "error" (technically it's just a warning) is saying that you do not need to escape [
in the regex when it is inside a character set ([]
syntax) because its meaning is unambiguous (you can't create nested character sets); ]
, on the other hand, does need to be escaped because it will be interpreted as part of the regex syntax that ends the character set instead of a literal ]
character.
简化示例:
/[\[]/
^ unnecessary escape
应该是:
/[[]/
这篇关于电子邮件验证的正则表达式规则在 vuejs 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论