c#

位置:IT落伍者 >> c# >> 浏览文章

C#验证邮件的正则表达式的代码


发布日期:2024年08月21日
 
C#验证邮件的正则表达式的代码

验证输入的正确性

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 );

               

上一篇:C#编程入门三部曲:增加响应用户事件代码

下一篇:一目了然,让你了解ADO.NET的命名规则