熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#驗證郵件的正則表達式的代碼

2022-06-13   來源: .NET編程 

  驗證輸入的正確性

  public static bool isEmail( string inputEmail )

  {

  inputEmail = NulltoString( inputEmail );

  string strRegex = @^( [azAZ_]+ )@( ( [[]{}[]{}[]{} )|( ( [azAZ]+ )+ ) )( [azAZ]{}|[]{} )( ]? )$;

  Regex re = new Regex( strRegex );

  if ( reIsMatch( inputEmail ) )

  return ( true );

  else

  return ( false );

  }

  驗證郵件地址的正確性

  string[] host = ( addressSplit( @ ) );

  string hostname = host[];

  IPHostEntry IPhst = DnsResolve( hostname );

  IPEndPoint endPt = new IPEndPoint( IPhstAddressList[] );

  Socket s= new Socket( endPtAddressFamily SocketTypeStreamProtocolTypeTcp );

  sConnect( endPt );

  //Attempting to connect

  if( !Check_Response( s SMTPResponseCONNECT_SUCCESS ) )

  {

  sClose( );

  return false;

  }

  //HELO server

  Senddata( s stringFormat( HELO {}rn DnsGetHostName( )) );

  if( !Check_Response( s SMTPResponseGENERIC_SUCCESS ) )

  {

  sClose( );

  return false;

  }

  //Identify yourself

  //Servers may resolve your domain and check whether you are listed in BlackLists etc

  Senddata( s stringFormat( MAIL From: {}rntestexampleuk ) );

  if( !Check_Response( s SMTPResponseGENERIC_SUCCESS ) )

  {

  sClose( );

  return false;

  }

  //Attempt Delivery ( I can use VRFY but most SMTP servers only disable it for security reasons )

  Senddata( s address );

  if( !Check_Response( s SMTPResponseGENERIC_SUCCESS ) )

  {

  sClose( );

  return false;

  }

  return ( true );


From:http://tw.wingwit.com/Article/program/net/201311/12817.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.