Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Regular Expression - allow emails with period in the name.

Posted on 2015-02-12
4
Medium Priority
?
114 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 1000 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 1000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)

609 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