Regular Expression - Allow multiple periods in emails

I have the following regular expression:
function regIsEmail(fData){ 
				var reg = new RegExp("^[0-9a-zA-Z]+@[0-9a-zA-Z]+[\.]{1}[0-9a-zA-Z]+[\.]?[0-9a-zA-Z]+$"); 
				return reg.test(fData); 

Open in new window

the problem is, this expression does not allow email addresses like:
An email in this format gets rejected.  I personally would reject it for being annoying, but that's not the point.

What do I need to change to make this work?

Thanks for your help!!!

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.



var reg = new RegExp("^[0-9a-zA-Z]+@(?:[A-Z0-9-]+\.)+?[0-9a-zA-Z]+$");

Anthony FitzgeraldVP Technology & LocalizationCommented:

There are probably a few different ways. How about using the look ahead and look behind to check that they don't start or end with a period and then just allow any numbers/characters and period, something like this:

var reg = new RegExp("^(?!\.)[0-9a-zA-Z\.]+(?<!\.)@(?!\.)[0-9a-zA-Z\.]+(?<!\.)$");

slightlyoffAuthor Commented:
Hello!  Thank you for your replies!  I tried the second code first from Anthony - something is wrong with that one, it breaks the javascript and the form won't submit.

I tried the one from Rgonzo1971 next, and that one won't let the periods in the email.  I tried using:

I get invalid email.

Any advice?  thanks again for your help!!!
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Anthony FitzgeraldVP Technology & LocalizationCommented:
My RegEx expression works fine when I tested it.
But of course you are using JavaScript. RegEx Look Behind is not supported in JavaScript. That sucks.

Try this without the Look Behind instead. I haven't tested it in JavaScript, but I have tested it in another tool and it works.

var reg = new RegExp("^(?!\.)[0-9a-zA-Z\.]+[0-9a-zA-Z]@(?!\.)[0-9a-zA-Z\.]+[0-9a-zA-Z]$");

Let me know how you get on.

slightlyoffAuthor Commented:
Thanks again for your help!  After putting in the new Regex, it triggers an invalid email when i try  With my original regex expression, I can get email's like this to work,  but the moment i try it doesn't work.
Anthony FitzgeraldVP Technology & LocalizationCommented:
Its the correct syntax. Unless it just doesn't fit well with JavaScript.

I have saved it here on RegExr, so you can see it working.

For some reason you can't see my web links in these comments.
Have a look here:

Also this is cool site for testing your RegEx, you can play around with it.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anthony FitzgeraldVP Technology & LocalizationCommented:
Well, how did you get on? Did you get it working in the end?
slightlyoffAuthor Commented:
Sorry for the delay - they had me on other projects, and i finally got back to it.
It's working now.  People need to have more simple email addresses in my humble opinion.

Thanks again!

käµfm³d 👽Commented:
Personally, I'd use the pattern found here:

...for the reasons the author outlines.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.