Solved

regular expresssion email apostrophe

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

822 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