Solved

Regular Expression - allow emails with period in the name.

Posted on 2016-08-17
4
67 Views
Last Modified: 2016-08-17
I had ran into an issue previously where my regex expression wasn't allowing periods in the name for emails.  for example, my.email@gmail.com wouldn't work.  Thanks to the fine experts at Experts-Exchange, that is working now.

However, email addresses like my.email75@gmail.com or myemail.11@gmail.com don't work.  Here's my expression & the function i'm using:

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


To me it looks like it's allowing numbers - so I'm not sure  what needs to be changed.  Any suggestions?
0
Comment
Question by:slightlyoff
  • 2
4 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 41759541
I'd go here to find an email validation regex. There are loads:

http://www.regexlib.com/RETester.aspx?regexp_id=26
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 41759614
Try:

function regIsEmail(fData){ 
 				
				var reg = new RegExp("^[0-9a-zA-Z\_]+ (?:\.[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

0
 
LVL 1

Author Closing Comment

by:slightlyoff
ID: 41759712
Thank you for your help!  that worked great!
0
 
LVL 1

Author Comment

by:slightlyoff
ID: 41759714
Thank you Lee - I did go there, but finding an expression that had all the components was difficult.  now that people can make email addresses like my_name.75@gmail.co.uk it's getting kind of crazy out there...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

860 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