Email-Validation using C#.net
Hi Friends,
How to validate an Such an Email-id : test.test-test@test-med.com [One of my customer having such an mail-id]
Im validating using regular expression in C#.net:
string pattern = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|" +
@"0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*([-][a-z|0-9]+)*\.([a-z]" +
@"[a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";
System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(editemail.Text.Trim(), pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (!match.Success)
{
MessageBox.Show("You must specify valid E-mail", this.vGlobalVariables.gProductVersion, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.editemail.Focus();
}
While using the above code its saying You must specify valid email.
How to validate the above email-id [test.test-test@test-med.com]?
Thanks
Divakar
All Replies
- Send an email to the address and have the user click a link to verify ownership of the email.
useCode Snippetstring pattern = @"[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|].[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]@test-med.com";
if the address will terminate in @test-med.com
or
Code Snippetstring pattern2 = @"[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|].[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]@[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|].[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]-[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|].[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|].com";
if the address will be something like ***-***@***-***.com
i hope you got my point.
Thanks for ur valuable code...
Thanks
Divakar
glad i could be of helpYou may find it useful to understand the logic behind the regex.
http://www.regular-expressions.info/email.html
- hi,
This is good sample
regards,
ramesh.v hi,
I would like to validate domain ID given in the txt_email (Textbox), if the valid domain id is given, i will let the user to submit the form otherwise not...
can anyone help me asap, thanks in advance.
This is my code:-
public static bool IsDomainExistence(string strEmailID)
{
try
{
string[] host = (strEmailID.Split('@'));
string hostname = host[1];
IPHostEntry IPhst = Dns.GetHostEntry(hostname);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
s.Connect(endPt);
}
catch (Exception)
{
return false;
}
return true;
}
It works fine in local, but when it is uploaded to server, it produces error message, even-if our domain id is given.
regards,
Balamurugan- Original posting --> Wednesday, April 30, 2008 1:39 PM
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com - I have found this one NetXtreme Email Verifier Component . It is good for me, hope this helps you.
- Hi all,
in my company we use EmailVerify.NET (http://www.emailverify.net), a Microsoft .NET component which supports e-mail syntax checking, domain MX test and mailbox validation too.
E-mail validation up to the mailbox level is easy as writing the following code block:
var verifier = new EmailVerifier(); var result = verifier.Verify("me@example.com", VerificationLevel.Mailbox); if (result.IsSuccess) { // Go on, send the message }
Additional code samples can be found here.
From their home page:
EmailVerify.NET is a powerful .NET component which verifies email addresses using various techniques, including:- Syntax verification, according to RFC 2821 and RFC 2822
- MX record lookup
- Disposable email address (DEA) validation
- SMTP availability check
- Mailbox existence check, with greylisting support
- Catch-all test
It is completely written in managed code (C#) and is compliant with the Common Language Specification (CLS), so it can be used with any other .NET language, including VB.NET, C++/CLI, J#, IronPython, IronRuby and F#.
The price for this component is very small (less than 50 bucks) and their support is one of the greatest I've ever found for a small software company like they are.
Hope this helps.


