Solved

Regular Expression - allow emails with period in the name.

Posted on 2015-02-12
4
104 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
ID: 40606522
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
ID: 40607055
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
ID: 40609478
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
ID: 40612336
Thank you both for your help!

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

Thanks again!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

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…
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…
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 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…

808 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