?
Solved

Regular Expression that supports foreign email address characters

Posted on 2014-01-08
8
Medium Priority
?
887 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
[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
  • 5
  • 2
8 Comments
 
LVL 33

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 13

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
Industry Leaders: 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!

 

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
 
LVL 13

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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
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…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

764 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