[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3035
  • Last Modified:

how to validate email address format asp.net c#

I need the best way probably to validate a load of email addresses  these can be in the format of
test@test.co.uk
test@test.com
test@test.ca

etc
0
mugsey
Asked:
mugsey
  • 2
1 Solution
 
vb_jonasCommented:
Hi, it's common to use a regular expression to test for valid email address:

Dim strMailAddress As String
Const pattern As String = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

Dim rgRegEx As New System.Text.RegularExpressions.Regex(pattern,
System.Text.RegularExpressions.RegexOptions.Compiled)

If rgRegEx.IsMatch(strMailAddress) Then
 ' Valid
End If
0
 
mugseyAuthor Commented:
Yeahh but would it validate .ca  .co.uk   .com    ??
0
 
vb_jonasCommented:
It would accept all top-domains.

Here are a more flexible test that does not use regex. http://www.developerfusion.co.uk/show/3350/

0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now