Solved

regular expresssion email apostrophe

Posted on 2009-05-08
3
580 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

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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 count occurrences of each item in an array.
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…

930 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

13 Experts available now in Live!

Get 1:1 Help Now