验证电子邮件地址是否包含“@”和“。”

发布于 2024-11-06 20:13:43 字数 65 浏览 6 评论 0原文

我需要验证插入的电子邮件地址是否包含“@”和“.”没有正则表达式。 有人能给我“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

影子的影子 2024-11-13 20:13:43

怀疑你正在追求类似的东西:

if (!address.contains("@") || !address.contains("."))
{
    // Handle bad address
}

编辑:当然,这远不是一个完整的验证。这只是验证的开始 - 但希望这能让您继续处理您想要处理的特定情况。

I suspect you're after something like:

if (!address.contains("@") || !address.contains("."))
{
    // Handle bad address
}

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.

指尖微凉心微凉 2024-11-13 20:13:43

根据我的个人经验,验证电子邮件地址的唯一方法是发送带有验证链接或代码的电子邮件。
我尝试了很多验证器,但它们并不完整,因为电子邮件地址可能非常松散......

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 ...

故人如初 2024-11-13 20:13:43
int dot = address.indexOf('.');
int at = address.indexOf('@', dot + 1);

if(dot == -1 || at == -1 || address.length() == 2) {
  // handle bad address
}

这不是完整的解决方案。您必须检查 @ 和仅包含“.”的地址是否多次出现。和 '@'。

int dot = address.indexOf('.');
int at = address.indexOf('@', dot + 1);

if(dot == -1 || at == -1 || address.length() == 2) {
  // handle bad address
}

This is not complete solution. You will have to check for multiple occurances of @ and address with only '.' and '@'.

木緿 2024-11-13 20:13:43

如果不允许使用正则表达式,请使用 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.

旧人哭 2024-11-13 20:13:43

您可以搜索第一个“@”,然后检查“@”左侧是否是有效字符串(即没有空格或其他内容)。之后,您应该在右侧搜索“.”,并检查两个字符串是否有有效域。

这是一个相当弱的测试。无论如何,我建议使用正则表达式。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文