Regex email verification error - using JavaScript

我只是一个虾纸丫 提交于 2019-12-04 21:09:24

You need to use a regex that actually fits for an email address. Your current one is completely broken as there are tons of valid addresses it won't accept.

See http://www.regular-expressions.info/email.html for a more detailed description and arguments why a regex is not such a good idea after all.

Anyway, here's one that probably fits for your needs:

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

Here's what regular-expressions.info says about this regex:

We get a more practical implementation of RFC 2822 if we omit the syntax using double quotes and square brackets. It will still match 99.99% of all email addresses in actual use today.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!