Solved

Regular Expression - allow emails with period in the name.

Posted on 2015-02-12
4
105 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…
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 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)

756 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