Solved

Regular Expression - allow emails with period in the name.

Posted on 2015-02-12
4
102 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…
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)

911 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

27 Experts available now in Live!

Get 1:1 Help Now