sim.plified.com

Chris Pollock

Chris Pollock - web developer & ecommerce entrepreneur
undivided… my thoughts on world, family, church, business, technology and Jesus Christ (all in all)

Check Email with Regular Expressions (Regex)

For web developers, validating email addresses is just part of what it means to accept user input.  One of the challenges I find is that email validation does not often stay up to date with the changes in email.  For instance, Gmail allows for cool features like adding a +anything to the end of your email address.  Many regex email validation strings do not allow for this useful function.  Well, in designing the signup for patterntap.com I ran into this, when of course initially my regex did not allow for the gmail + or even a four letter domain name (e.g. .info)  So.. here is my updated regex for PHP.  Hope you find it userful, please comment if you find any issues with it.

// lets just make the email lowercase for the ALL CAPS people
$email = strtolower($_REQUEST["emailreal"]);

if (eregi("^[\.\+_a-z0-9-]+@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$", $email) ) {
   // now do something cool!
}

2 Comments, Comment or Ping

  1. I ran into both validation issues. I tried an .info address and and a gmail+ address on patterntab.com. ;)

    Everythings works fine now. Thanks!

Reply to “Check Email with Regular Expressions (Regex)”

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Things I see

IMG_7347BookFinally!Little peanutTime to set sailEyes openSleepy TimeAri Jeremiah PollockBig brotherBaby's HomeBike manBiker gangBirthday monopoly.$5 StarIMG_2881

Chris Pollock

Web Developer - proficient in both PHP and ASP.NET.
Rochester, New York

View my web developement site.

View Chris Pollock's LinkedIn profile

My Pictures

IMG_7347BookFinally!Little peanutTime to set sailEyes openSleepy TimeAri Jeremiah PollockBig brotherBaby's HomeBike manBiker gangBirthday monopoly.$5 StarIMG_2881