Solved

Regex for email

Posted on 2011-09-07
9
269 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…

708 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