在不使用正则表达式的情况下验证电子邮件 [英] validate email without using regular expression

查看:74
本文介绍了在不使用正则表达式的情况下验证电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我知道如何在不使用正则表达式的情况下验证电子邮件


在此先感谢>>

Let me know how to validate email without using regular expression


thanks in advance>>

推荐答案

如果不使用与它们一起使用的正则表达式,则很难对其进行验证.

1)计算"@"字符的数量-应该为一个.
2)检查域和本地地址的长度-本地限制为64个字符,并且该对的总长度为255个字符.
3)检查地址是否以非``.''字符结尾,但域中必须至少包含一个''.''.''
4)检查本地"和域"中是否存在非法字符:Wiki上有一篇介绍此内容的说明. http://en.wikipedia.org/wiki/Email_address [
It''s a lot harder to validate it without using regex that it is with them.

1) Count the number of ''@'' characters - it should be one.
2) Check the Domain and Local address lengths - the local is limited to 64 characters, and the total length of the pair is 255 characters.
3) Check that the address ends with a non ''.'' character, but the Domain must contain a minimum of one ''.''
4) Check the Local and Domain for illegal characters: there is a description on Wiki that covers this. http://en.wikipedia.org/wiki/Email_address[^] - look about 1/3 of the way down.

When you have checked all this, you will have a valid format email address. That does not mean it will work, or that it will last any longer than it takes you to test it. There are sites out there giving ten minute emails: they are destroyed after that.


你好

我在这里写的,没有测试代码,但是基础是正确的.
Hello

I wrote it here and didn''t test the code but the base is currect.
public bool IsEmailValid(string email)
{

    string[] chunks = email.Split('@');

    if (chunks.Count() != 2)
        return false;

    if (chunks[0].Length == 0 || chunks[1].Length < 3)
        return false;

    if(!chuncks[1].Contains["."])
        return false;

    if (!Char.IsLetter((chunks[0])[0]))
        return false;


    foreach (char c in email)
    {
        if (!Char.IsLetter(c) && !Char.IsNumber(c) && c != '_' && c != '.' && c != '@')
            return false;
    }

    if (email.Contains("..") || email.Contains(".@") || email.Contains("@.") || email.Contains("._."))
        return false;

    if (email.EndsWith("."))
        return false;

    return true;
}


这篇关于在不使用正则表达式的情况下验证电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆