Validating emails

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have this problem that client users enter emails incorrectly due to type
and either the domain name is invalid (Microsot.com instead of
Microsoft.com) or the syntax of the email (user'domain.com instead of
(e-mail address removed)). Is there any way to ensure a) email syntax is correct and
b) reverse dns or any other check to highlight invalid domain names?

Thanks

Regards
 
public const string
RegexValidEMail = @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$";


static public bool IsValidRegexValidEMail (string ValueToTest)
{ return Regex.IsMatch(ValueToTest, RegexValidEMail); }
 
That's C#. Translated to VB:

Imports System.Text.RegularExpressions

Public Function IsValidRegexValidEMail(ByVal ValueToTest As String) As
Boolean
Const RegexValidEMail As String =
"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"
IsValidRegexValidEMail = Regex.IsMatch(ValueToTest, RegexValidEMail)
End Function

Regular expression doesn't check the length of the address and may miss
few valid addresses with special chars. See
http://en.wikipedia.org/wiki/E-mail_address

Checking domains requires a third party component as far as I know. If
someone
knows a way how to do it in VB I'd like to know too.

In the first place checking domains (or MX records) may not be feasible. It
tends to
be slow unless you have only a few email address.

- Timo
 
John said:
I have this problem that client users enter emails incorrectly due to type
and either the domain name is invalid (Microsot.com instead of
Microsoft.com) or the syntax of the email (user'domain.com instead of
(e-mail address removed)). Is there any way to ensure a) email syntax is correct
and b) reverse dns or any other check to highlight invalid domain names?

Parsing Email Addresses using an RFC822 Compliant Address Validator
<URL:http://www.codeproject.com/csharp/RFC822Validator.asp>
 
I'm not an expert with email, but, here is how I'd do it...

Step1] Do the RegEd code to check format of email.
Step2] I'd figure out a way to test if the email address is valid by sending
it and checking the receipt of the email (if this can be done in .net or via
your email service).
Step3] If the email is valid then add it to a database table.
Step4] On all future email send commands then do a lookup against the
database table for the email. If email has been previously sent with out
issues then all user to keep going and send the email. Otherwise, kick up a
message box asking user if they have a valid email address.

You could also do a check against your global address book in your email
system (Outlook) or in Active Directory. If your using Acitve Directory
then you can use .net code to see your network wide addresses if you have
admin authority.

Hope this helps! JerryM
 
Back
Top