Solved

regular expresssion email apostrophe

Posted on 2009-05-08
3
577 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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks this option works better for me
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
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…
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.

743 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

11 Experts available now in Live!

Get 1:1 Help Now