Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Regex for email

Posted on 2011-09-07
9
Medium Priority
?
280 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
[X]
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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…

730 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