正则表达式检查电子邮件是否有效以及是否超过一个字符
我正在尝试使用此正则表达式 .*@.*\..*
验证电子邮件地址,我只是想知道如何更改它以检查字符串是否超过一个字符?
im trying to validate an email address with this regular expression .*@.*\..*
im just wondering how i can change this to also check if the string is more than one character?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用
+
说明符而不是*
来确保至少有一个字符:这实际上将确保至少有五个字符,因为您不能拥有一个比这更有意义的公共电子邮件地址。您可以进行更详细的检查(例如根据域名的最小长度和允许的字符),但这至少涵盖了最基本的要求。
Use the
+
specifier instead of*
to make sure that there is at least one character:This will actually ensure that there is at least five characters, as you can't have a public email address that makes sense with less than that. You could make a more elaborate check (for example based on the minimum length of domain names and the allowed characters), but this at least covers the most basic requirements.
您不需要使用正则表达式进行长度检查,只需使用字符串长度选项:
另外我建议不要验证电子邮件地址。它非常复杂,请参阅此问题以获取更多信息:
使用用于验证电子邮件地址的正则表达式
You don't need to do length checks with Regex, just use the string length option:
Also I would recommend not validating email addresses. It's insanely complicated, see this question for more information:
Using a regular expression to validate an email address
使用正则表达式验证电子邮件地址并非易事。请参阅此处和此处。
Validating email addresses with a regex is non-trivial. See here and here.
.+@.*\..*
也可以做到这一点.+@.*\..*
would also do the trick使用下面的电子邮件验证
使用下面的长度
Use below for email validation
Use below for length