验证电子邮件地址是否包含“@”和“。”
我需要验证插入的电子邮件地址是否包含“@”和“.”没有正则表达式。 有人能给我“java代码”和“结构图”的例子吗?
i need to validate that an inserted email address contains "@" and "." without a regular expression.
Can somebody to give me "java code" and "structure chart" examples please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我怀疑你正在追求类似的东西:
编辑:当然,这远不是一个完整的验证。这只是验证的开始 - 但希望这能让您继续处理您想要处理的特定情况。
I suspect you're after something like:
EDIT: This is far from a complete validation, of course. It's barely even the start of validation - but hopefully this will get you going with the particular case you wanted to handle.
您可以使用
commons-validator
,特别是EmailValidator.isValid()
You can use
commons-validator
, SpecificallyEmailValidator.isValid()
根据我的个人经验,验证电子邮件地址的唯一方法是发送带有验证链接或代码的电子邮件。
我尝试了很多验证器,但它们并不完整,因为电子邮件地址可能非常松散......
From my personal experience, the only was to validate an email address is to send a email with a validation link or code.
I tried many of the validator but they are not complete because the email addresses can be very loose ...
这不是完整的解决方案。您必须检查 @ 和仅包含“.”的地址是否多次出现。和 '@'。
This is not complete solution. You will have to check for multiple occurances of @ and address with only '.' and '@'.
如果不允许使用正则表达式,请使用 String.indexOf,但我建议您不要在输入期间验证地址。
最好发送一封激活电子邮件。
Use String.indexOf if you aren't allowed to use regexp, and but I would adwise you to not validate the address during input.
It's better to send an activation email.
您还可以使用 Java 邮件 API。具体来说,这里:
http:// /javamail.kenai.com/nonav/javadocs/javax/mail/internet/InternetAddress.html#InternetAddress(java.lang.String, 布尔值)
You can also use the Java Mail API. Specifically, here:
http://javamail.kenai.com/nonav/javadocs/javax/mail/internet/InternetAddress.html#InternetAddress(java.lang.String, boolean)
您可以搜索第一个“@”,然后检查“@”左侧是否是有效字符串(即没有空格或其他内容)。之后,您应该在右侧搜索“.”,并检查两个字符串是否有有效域。
这是一个相当弱的测试。无论如何,我建议使用正则表达式。
You can search for the first '@', then check if what you have at the left of the '@' is a valid string (i.e. it doesn't have spaces or whatever). After that you should search in the right side for a '.', and check both strings, for a valid domain.
This is a pretty weak test. Anyway I recommend using regular expressions.