Solved

Regular Expression that supports foreign email address characters

Posted on 2014-01-08
8
762 Views
Last Modified: 2014-01-18
The regular expression I use for email address validation is

\w+([-+!$%&*/=?{|}.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

which I think is pretty standard but it doesn't support foreign characters such as

Ébaker@mydemo.com

Can anyone recommend a better expression?

Note I have come across this:
http://stackoverflow.com/questions/16454939/regex-to-validate-international-email

which seems to suggest using
[^\s@]+@[^\s@]+\.[^\s@]+

which appears more flexible but apparently does allow for example test@hello..com

Can someone tell me what the above expression is actually doing?

I know there is also this http://ex-parrot.com/~pdw/Mail-RFC822-Address.html which obviously seems like overkill (and interestingly doesn't seem to allow some of the foreign character examples the above expression does).

Also I'm using .net which may impact this as some of the "regex" testing sites seemed to think my original regex expression did actually allow my foreign example email address, but my ,net aspx page certainly doesn't allow it.
0
Comment
Question by:purplesoup
  • 5
  • 2
8 Comments
 
LVL 32

Expert Comment

by:Big Monty
ID: 39766161
If all you want to match is letters (including "international" letters) you can use \p{L}
0
 

Author Comment

by:purplesoup
ID: 39767694
You mean this?

Doesn't seem to work - doesn't even validate standard email addresses

\p{L}+([-+!$%&*/=?{|}.']\p{L}+)*@\p{L}+([-.]\p{L}+)*\.\p{L}+([-.]\p{L}+)*
0
 
LVL 12

Expert Comment

by:Jitendra Patil
ID: 39767889
try the below link, may be of use to you.
How To Validate An Email Address
hope this helps.
0
 

Author Comment

by:purplesoup
ID: 39768574
He seems to be suggesting this

^(?!\.)("([^"\r\\]|\\["\r\\])*"|([-a-z0-9!#$%&'*+/=?^_`{|}~] |(?@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$

Open in new window


but all the regex online testing sites I've tried it on say it isn't valid...
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 12

Expert Comment

by:Jitendra Patil
ID: 39770675
hi can you try some more from the below link
email address (RFC 2822 mailbox)
hope this helps.
0
 

Author Comment

by:purplesoup
ID: 39771077
Hmm - not really sure what to make of these suggestions - you've posted a link to a whole page of email validator expressions, none of which work with foreign email addresses. That's about 21 expressions that don't work.

I'm testing it here:
http://www.freeformatter.com/regex-tester.html
0
 

Accepted Solution

by:
purplesoup earned 0 total points
ID: 39776143
I went with this one in the end

[^\s@]+@[^\s@]+\.[^\s@]+
0
 

Author Closing Comment

by:purplesoup
ID: 39790432
I found the answer from searching in the end - I couldn't get any of the suggested solutions to actually work.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

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

13 Experts available now in Live!

Get 1:1 Help Now