Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Regex for email

Posted on 2011-09-07
9
Medium Priority
?
289 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 2000 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
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!

 
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
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…

885 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