VB.NET
Public Shared Function IsValidMailAddress(address As String) As Boolean
If String.IsNullOrEmpty(address) Then
Return False
End If
Try
Dim a As New System.Net.Mail.MailAddress(address)
Catch ex As FormatException
'正しくない
Return False
End Try
Return True
End Function
C#public static bool IsValidMailAddress(string address)
{
if (string.IsNullOrEmpty(address))
{
return false;
}
try
{
System.Net.Mail.MailAddress a =
new System.Net.Mail.MailAddress(address);
}
catch (FormatException)
{
//正しくない
return false;
}
return true;
}