Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

regular expresssion email apostrophe

Posted on 2009-05-08
3
Medium Priority
?
591 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 2000 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
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…
Suggested Courses

730 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