• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

validate a email address format in a Console Application

I have a console application that sends emails, but I am having a problem with my email source of haveing invalid email formats I.E.  name@@yahoo.com, name@yahoo, nameyahoo.com.

I just need to validate the format is correct, being an console application there is no user input or enter action

here is my code

                If chkVEmail(vEmail) = False Then
                    .To = "SUGARLANDSUPPLIERQUALITY@suntroncorp.com"
                    .Subject = "Vendor Email for " + strVen + " is formated wrong"
                end if
the  ChkVEmail if where I will be validating the email (one name at a time)
0
LeeHopkins
Asked:
LeeHopkins
  • 3
  • 2
  • 2
  • +1
1 Solution
 
MasterThaiCommented:
use reg expressions
this regx will validate if its a valid email or not.
\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

0
 
LeeHopkinsAuthor Commented:
how would I use that in a function I understand how to use it in a Regx on a form with a text box
0
 
rfgkevCommented:
'being an console application there is no user input or enter action'

try Console.Read() or Console.ReadLine()
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LeeHopkinsAuthor Commented:
I have a function that I want to return a True or False of the Email format
How would I use \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* in the function

IE

Private Function chkVEmail(ByVal venemail As String) As Boolean

if venemail = (here is my problem)
return venemail = true

else

return venemail = false
end if

return venemail



end function
0
 
Fernando SotoCommented:
Hi LeeHopkins;

Here is your function using MasterThai pattern.

Imports System.Text.RegularExpressions

    Private Function chkVEmail(ByVal venemail As String) As Boolean

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

        If Regex.IsMatch(venemail, pattern) Then
            Return True
        Else
            Return False
        End If

    End Function


Fernando
0
 
rfgkevCommented:
Private Function chkVEmail(ByVal venemail As String) As Boolean
        Return System.Text.RegularExpressions.Regex.IsMatch(venemail, "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")
End Function
0
 
LeeHopkinsAuthor Commented:
Thanks I will give that a try,
so that is doing the same as if i had put a reg exp valid on a form and put that string in,
Why does none of MS docuemtation talk about using it during run time

0
 
Fernando SotoCommented:
Hi Bob;
I would like to see a resolution to this question seeming I gave working code.

Thanks;
Fernando
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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