Solved

regular expresssion email apostrophe

Posted on 2009-05-08
3
584 Views
Last Modified: 2012-05-06
I need to do email verification in a PHP script that I have and I was using the below regular expression to verify that the email is valid.

^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$

but I recently ran into a valid user that has an apostrophe in is email like:

john.o'sullivan@domain.com

Can anyone help me modify the above expression or provide me with a better expression that will validate the above email?
0
Comment
Question by:battalion
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 24336859
fred&barney@stonehenge.com
is also a valid email address
unless you want a 6000 byte long regular expression to validate the  RFC-2822 mail header standard
you may be better off with something like
^.*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$
0
 

Expert Comment

by:smjunk
ID: 24340184
just add apostrophe to the list of characters  in the square brackets like this
^['_a-z0-9-]+(\.['_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$
0
 

Author Closing Comment

by:battalion
ID: 31579448
thanks this option works better for me
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

Suggested Solutions

Title # Comments Views Activity
how to use a switch statement with heredoc 11 33
What does this formatting equate to? 7 18
Log in through ID 5 19
Ajax and PHP 9 31
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

830 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