Tiffany B. Brown

a mish-mosh of stuff

A pattern for matching e-mail addresses

I recently published a better pattern for matching e-mail addresses than this one.

A regular expression pattern for use in JavaScript, PHP, or whatever language you use that supports them.

^[-a-z0-9._+]+@[-a-z0-9._]+\\.[-a-z0-9._]{2,6}$

The details

  • Supports addresses with periods and plus signs (e.g. ‘tiffany.brown’ or ‘hotc0derch1ck+todolist’)
  • Supports top-level British and Australian domain names such as ‘.co.uk’ and ‘.com.au’
  • Supports new top-level domains including ‘.museum’ and ‘.travel’
  • May need to use a case-insensitive modifier
  • Should convert the string to lower case and trim whitespace from each end before comparting to the pattern.

Improvements? Questions? Share with us in the comments.

More information

  • http://bkaeg.org/ AG

    Oh, how I love regex. The string you’ve listed is a classical example. Works well in any scripting language.

  • http://bkaeg.org AG

    Oh, how I love regex. The string you’ve listed is a classical example. Works well in any scripting language.