Regular expression for e-mail Posted on June 16th, 2005 by

Regular expressions can be very useful and efficient if used properly. For a while now in some of our applications we have been using the following regular expression to check e-mail addresses for proper formatting.

^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*.(([a-z]{2,3})|(aero|coop|info|museum|name))$

This will ensure that the user has entered a properly formatted e-mail address such as user@domain.com.

Contact Us

Phone: 507-933-6111
Email: helpline@gustavus.edu
Web: https://gustavus.edu/gts
Blog: https://gts.blog.gustavus.edu
Remote Support: https://sos.gac.edu
System Status: https://gustavus.freshstatus.io

Sign up for our newsletter.

Receive a daily digest anytime we post something new.

We don’t spam! Unsubscribe at any time!

 


4 Comments

  1. John Michael Pierobon says:

    This is fantastic.
    But, how do you validate for an address of
    the following format
    first.last@something.abc.af.mil
    or
    first.longlast@long.base.navy.mil

  2. Ryan Rud says:

    This regular expression has been updated to check for capitalization in e-mail addresses.

  3. […] We discovered a small bug in our old regular expression for checking valid e-mail addresses. When a user tried to use an address with capital letters on a form, it failed to match the regular expression. We updated the regular expression to account for capital letters anywhere in the e-mail address. […]

  4. Ryan Rud says:

    Don’t forget about arpa!! The expression should be ^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|arpa|coop|info|museum|name))$