Solved

Regex for email

Posted on 2011-09-07
9
273 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 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

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…
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…

749 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