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
- Regex.info
- Using Regular Expressions by Stephen Ramsay
- Regular Expression HOWTO by A.M. Kuchling (Python-specific, but the concepts are portable)
- Perl-compatible regular expressions
- PHP Perl-compatible regular expressions
- JavaScript Regular Expressions