码迷,mamicode.com
首页 > 其他好文 > 详细

判断邮箱格式是否正确

时间:2015-02-05 21:51:00      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

//    是否是 合法邮箱
BOOL IsValidEmail(const CString strEmail)
{
    if( strEmail.GetLength() < 5 ) //26个小写字母
    {
        return FALSE;
    }
    char ch;

    int atCount =0;
    int atPos = 0;
    int dotCount = 0;
    for(int i=0; i<strEmail.GetLength(); i++) //  从0 开始判断
    {
        ch = strEmail[i];
        if( IsValidChar(ch) )
        {
            if(ch==64) //"@"
            {
                atCount ++;
                atPos = i;
            }
            else if( (atCount>0) && (ch==46) )//@ 符号后的"."号
            {
                dotCount ++;
            }
        }
        else
        {
            return FALSE;
        }
    }
    //6. 结尾不可以是字符 "@" 或者 "".
    if( ch == 46 )
    {
        return FALSE;
    }
    //2. 必须包含一个 并且 只有一个符号“@”
    //3. @  后必须包含至少一个至多三个符号"."
    if( (atCount!=1) || (dotCount<1) || (dotCount>3) )
        return FALSE;
    //5. 不允许储蓄“@.” 或者 ".@"
    int x=-1, y=-1;
    x=strEmail.Find(_T("@."));
    y=strEmail.Find(_T(".@"));
    if( x>0 || y>0 )
    {
        return FALSE;
    }
    return TRUE;
}

 

参考文:

  http://blog.sina.com.cn/s/blog_7f2cb66b0100t3l4.html

判断邮箱格式是否正确

标签:

原文地址:http://www.cnblogs.com/wjxx836/p/4275963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!