Solved

how to validate email id without using regular expression

Posted on 2008-06-26
6
1,181 Views
Last Modified: 2013-12-16
how to validate email id without using regular expressions.
USING:- MICROSOFT VISUAL STUDIO2005
0
Comment
Question by:pooja
  • 2
6 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 84 total points
ID: 21873722
Can I ask you why you don't want to use a regular expressions?

You can always use those rules:
-requires a @ character
-the @ character cannot be the first one
-a . is required after the @
-at least 1 character is required between the @ and the .
-at least 1 character is required after the .
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 83 total points
ID: 21873724
Why aren't you using regular expressoins for it ?
Imports System.Text.RegularExpressions     

Function EmailAddressCheck(ByVal emailAddress As String) As Boolean

Dim pattern As String = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"        

Dim emailAddressMatch As Match = Regex.Match(emailAddress, pattern)        

If emailAddressMatch.Success Then

            EmailAddressCheck = True

Else            

            EmailAddressCheck = False        

End If     

End Function

Open in new window

0
 
LVL 7

Assisted Solution

by:joesthebighmoe
joesthebighmoe earned 83 total points
ID: 21874998
You can rely on the .Net framework....



public bool IsEmailValid(string iEmail)

{

  bool oIsEmailValid = true; //until proven false

    try

    {

      MailMessage Msg = new MailMessage();

      Msg.To.Add(iEmail);

    }

    catch

    {

      //Email addresses cannot be added if the mail message thinks they are invalid

      oIsEmailValid = false;

    }

    

    return oIsEmailValid;

}

Open in new window

0
 
LVL 7

Expert Comment

by:joesthebighmoe
ID: 22204048
Usually I would not bother with this since so much opinion is involved, however your recommendation seems strange.
The user asked how to validate email without regular expressions.
emoreau & Dhaest both asked why you would not want to use regular expressions.
I actually answered his question.
That said, do what you will.
-Cheers,
Joe
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now