Email Address Validation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

How to validate an email address in windows application

Thanks in advance
 
Public Shared Function IsValidEmail(ByVal strIn As String) As Boolean

' Return true if strIn is in valid e-mail format.

Return Regex.IsMatch(strIn,
("^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA
-Z]{2,4}|[0-9]{1,3})(\]?)$"))

End Function
 
Oops!!!

Either add
Imports System.Text.RegularExpressions

to the top of your class, or add System.Text.RegularExpressions. to the
front of regex
 
Public Shared Function IsValidEmail(ByVal strIn As String) As Boolean

' Return true if strIn is in valid e-mail format.

Return Regex.IsMatch(strIn,
("^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA
-Z]{2,4}|[0-9]{1,3})(\]?)$"))

End Function


There are many valid email addresses that expression will not validate. The
only serious regex attempt I've seen to match an address, according to the
relevant RFC, was about an entire page long.
 
Your best bet is to verify the email address by using a powerful email
validation webservice. This will tell if the email address exists on the
remote mail server. I remember seeing one a while ago. I'll see if I can
find the address for you.

Public Shared Function IsValidEmail(ByVal strIn As String) As Boolean

' Return true if strIn is in valid e-mail format.

Return Regex.IsMatch(strIn,
("^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-z
A
-Z]{2,4}|[0-9]{1,3})(\]?)$"))

End Function


There are many valid email addresses that expression will not validate. The
only serious regex attempt I've seen to match an address, according to the
relevant RFC, was about an entire page long.


--
Abderaware
Fine Components For .NET
Turn on, tune in, download.
zane a@t abderaware.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top