Solved

how to validate email id without using regular expression

Posted on 2008-06-26
6
1,180 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

12 Experts available now in Live!

Get 1:1 Help Now