admin管理员组文章数量:1392073
This is a regular expression I found online that seems to do a great job at simple email address validation. The problem is it doesn't allow + in the email, like [email protected]
. I'm not great at regex, so how can I add support for a + without breaking the whole thing?
var regex = new RegExp( /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i );
This is a regular expression I found online that seems to do a great job at simple email address validation. The problem is it doesn't allow + in the email, like [email protected]
. I'm not great at regex, so how can I add support for a + without breaking the whole thing?
var regex = new RegExp( /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i );
Share
Improve this question
asked Jun 7, 2018 at 18:10
GavinGavin
8,0164 gold badges57 silver badges77 bronze badges
3
- See stackoverflow./q/4736/3001761, stackoverflow./q/22937618/3001761 – jonrsharpe Commented Jun 7, 2018 at 18:12
-
I don't think there's any reason to use the
RegExp
constructor if you're using the/exp/i
literal notation. – user47589 Commented Jun 7, 2018 at 18:13 - Where do you need to support the + sign in the middle or in the start or at any position ? – mostafa tourad Commented Jun 7, 2018 at 18:15
2 Answers
Reset to default 6Change the second [\w-]+
to [+\w-]+
([+\w0-9._-]+@[\w0-9._-]+\.[\w0-9_-]+)
本文标签: javascriptHow can I add support for a(plus sign) in this email validation regexStack Overflow
版权声明:本文标题:javascript - How can I add support for a + (plus sign) in this email validation regex? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744780370a2624672.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论