Solved

Regular Expression - allow emails with period in the name.

Posted on 2016-08-17
4
61 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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)

831 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