电子邮件验证的正则表达式规则在 vuejs 中不起作用

编程入门 行业动态 更新时间:2024-10-09 21:23:21
本文介绍了电子邮件验证的正则表达式规则在 vuejs 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-27 00:32:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1145664.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中不   电子邮件   规则   正则表达式   vuejs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!