Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Regex for email

Posted on 2011-09-07
9
272 Views
Last Modified: 2012-05-12
I have a doubt in writing regex for email ..i need it below:



Should have @ and a dot embedded. There should be at
least 3 letters or digits before and after @ as well as the dot
0
Comment
Question by:PeteEngineer
9 Comments
 
LVL 16

Accepted Solution

by:
disrupt earned 500 total points
ID: 36500501
I would take a look at this thread

http://stackoverflow.com/questions/5342375/c-regex-email-validation

Is there a good reason for your character limits?
0
 
LVL 16

Expert Comment

by:santoshmotwani
ID: 36500505
Try following :

\^[a-z\d.]{3,}@[a-z\d.]{3,}$


Hope this helps :

http://stackoverflow.com/questions/156430/regexp-recognition-of-email-address-hard
0
 
LVL 82

Expert Comment

by:hielo
ID: 36500601
Refer to the accepted solution here:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_27258550.html

The regex is will documented
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 35

Expert Comment

by:Terry Woods
ID: 36500608
This one is commonly used:

^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$

(Slightly modified from http://www.regular-expressions.info/email.html )

Modified to require 3 chars before the @:
^[A-Z0-9._%+-]{3,}@[A-Z0-9.-]+\.[A-Z]{2,4}$
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36500703
Note you'll need the ignore case option on for that last one. Some regex engines allow it to be turned on like this:

(?i)^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$

Others have an extra function parameter etc.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36500706
Or, instead of the ignore case option, you can just build it into the expression:

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 36501932
My favorite is this one:
/^\w+([\.\-]\w+)*@\w+([\.-]\w+)*\.\w{2,4}$/

Open in new window

And your requirment for three letters can be added like this:
/^(\w+[\.\-])*\w*[a-z]{3,}@[a-z]{3,}\w*([\.-]\w+)*\.\w{2,4}$/i

Open in new window

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 36501993
Or for VB.NET in ASP.NET page:
Response.Write(Regex.Match(strMyEmail,"^(?i:(\w+[\.\-])*\w*[a-z]{3,}@[a-z]{3,}\w*([\.-]\w+)*\.\w{2,4})$"))

Open in new window

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 36502009
For C# its like this:
Response.Write(Regex.Match(strMyEmail,@"^(?i:(\w+[\.\-])*\w*[a-z]{3,}@[a-z]{3,}\w*([\.-]\w+)*\.\w{2,4})$"));

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

792 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