zoukankan      html  css  js  c++  java
  • 今天写了个检测邮件格式的算法~~

    public class Check
        
    {
            
    public static bool CheckEmail(string EmailString)
            
    {
                
    bool Result=false;
                
    if(EmailString.Length>=3)
                
    {
                    
    bool atString=false;
                    
    bool dotString=false;
                    
    int atPosition=0,atCount=0;
                    
    int dotPosition=0;
                    
    string Postfix;
                    Postfix
    =EmailString.Substring(EmailString.Length-3,3);
                    Result
    =PostfixCheck(Postfix);
                    
    for(int i=0;i<EmailString.Length;i++)
                    
    {
                        
    if(EmailString.Substring(i,1)=="@")
                        
    {
                            atString
    =true;
                            atCount
    +=1;
                            atPosition
    =i;
                        }

                        
    if(EmailString.Substring(i,1)==".")
                        
    {
                            dotString
    =true;
                            dotPosition
    =i;
                        }

                    }

                    
    if(atString&&dotString&&atCount==1&&System.Math.Abs(atPosition-dotPosition)>1&&Result)
                        Result
    =true;
                    
    else
                        Result
    =false;
                }

                
    else
                    Result
    =false;
                
    return Result;

            }

            
    private static bool PostfixCheck(string PostfixString)
            
    {
                
    bool PostfixResult=false;
                
    string PostfixTableString="com|net|org|cn |jp |gov|edu|int|mil|biz|cc |tv |ac |au |de |fr |hk |tw |uk |us |"//要添加的后缀
                for(int i=0;i<PostfixTableString.Length;i+=4)
                
    {
                    
    if(PostfixString.ToUpper()==PostfixTableString.Substring(i,3).Trim().ToUpper()||PostfixString.Substring(1,2).ToUpper()==PostfixTableString.Substring(i,3).Trim().ToUpper())
                    
    {
                        PostfixResult
    =true;
                        
    break;
                    }

                }

                
    return PostfixResult;
            }

        }
  • 相关阅读:
    java高并发
    阿里网盘挂载到本地主机
    frp突破内网ip限制教程
    docker学习总结(流水线、redis集群、网络待)
    git\svn提交记录规范
    【寻径06】如何突破学习瓶颈学习笔记
    leetcode 每日一题解题859. 亲密字符串
    字符串格式的json字符串转换为json格式的字符串
    如何使用github发布自己的静态项目
    软考第一课总结考前介绍(1)
  • 原文地址:https://www.cnblogs.com/Random/p/400712.html
Copyright © 2011-2022 走看看