pzozulka
asked on
Regex Email Address
We have the below regex for an email address, in our ASP.NET application (C#).
It allows up to a maximum of two periods in the domain name (for ex: alex@jj.alex.ca). How do I modify it to allow up to three periods (ex: alex@jj.alex.ca.us)?
It allows up to a maximum of two periods in the domain name (for ex: alex@jj.alex.ca). How do I modify it to allow up to three periods (ex: alex@jj.alex.ca.us)?
^(\w[\w!\$&\*\-=\^`\|~#%\+/\?{}\.']*@[\-\w]+\.([a-zA-Z]\w*(\.\w+)?)\s*)(;\s*\w[\w!\$&\*\-=\^`\|~#%\+/\?{}\.']*@[\-\w]+\.([a-zA-Z]\w*(\.\w+)?)\s*)*$
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It appears to work, yes. I do think that your pattern would be easier to read if you ditched all of the unnecessary escapes. Most of those that are unnecessary are the ones inside of characters classes (i.e. square brackets).
ASKER
Thanks much.
P.S.
I should have said in the above:
I should have said in the above:
...after the one that's already there at the end.
ASKER
Like this?
(\w[\w!\$&\*\-=\^`\|~#%\+/ \?{}\.']*@ [\-\w]+\.( [a-zA-Z]\w *(\.\w+)?) (\.\w+)?\s*)(;\s*\w[\w!\$&\*\-=\^` \|~#%\+/\? {}\.']*@[\ -\w]+\.([a -zA-Z]\w*( \.\w+)?)(\.\w+)?\s*)*$
(\w[\w!\$&\*\-=\^`\|~#%\+/
Just the second one; get rid of the first one that you added (i.e. the first one that's in bold).
ASKER
Open in new window
Basically, I added ([\-\w]+\.)? after @[\-\w]+\.