Solved

Regular Expression that supports foreign email address characters

Posted on 2014-01-08
8
808 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 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 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
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.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

839 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