[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Regular Expression that supports foreign email address characters

Posted on 2014-01-08
8
Medium Priority
?
955 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 34

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

873 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