Solved

Regular Expression - allow emails with period in the name.

Posted on 2016-08-17
4
44 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you for your help!  that worked great!
0
 
LVL 1

Author Comment

by:slightlyoff
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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)

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now