Solved

Regular Expression - allow emails with period in the name.

Posted on 2015-02-12
4
101 Views
Last Modified: 2015-02-16
I have this RegExp:
var reg = new RegExp("^[0-9a-zA-Z]+@[0-9a-zA-Z]+[\.]{1}[0-9a-zA-Z]+[\.]?[0-9a-zA-Z]+$");

Open in new window


But  i need to allow email addresses like some.guy@gmail.com

Right now this kind of email is rejected.  I'm guessing _ would also be rejected.

Any ideas on what I need to change?  I was thinking:
var reg = new RegExp("^[0-9a-zA-Z.]+@[0-9a-zA-Z]+[\.]{1}[0-9a-zA-Z]+[\.]?[0-9a-zA-Z]+$");

but i don't want to take down the contact form if i'm wrong.

Thanks for your help!!!
0
Comment
Question by:slightlyoff
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
Comment Utility
Your change would work for your stated purpose,
although it will still reject valid email addresses such as
The Fred and Barney Comedy Team <fred&barney@stonehenge.com>

By the way the \ and {1} in your expression are unnecessary
0
 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 250 total points
Comment Utility
If you'd like to match the regex used by HTML5, I did a video tutorial on why you might like to use it: http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/VP_245.html

The pattern is:
^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$

Open in new window


Sourced from:
http://www.w3.org/TR/html-markup/input.email.html#input.email
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
That still rejects some valid email addresses, although addresses with quoted strings, comments, and Unicode may be less common.
0
 
LVL 1

Author Closing Comment

by:slightlyoff
Comment Utility
Thank you both for your help!

I will be giving it a try this week and see what happens.

Thanks again!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now