Email Validation Using Regular Expressions (the right way… really)
OK, I know this is the millionth blog post claiming to have the right way to validate email addresses, but here me out:
Regular expressions are awesome–and I mean Wrath of Kaaaaahn! awesome. They yield the unholy power to make or break your system, to secure or rip apart your entry points. Woven wisely, they can be magical. Woven foolishly, they can destroy you.
After spending way too long sifting through broken regular expressions, expecting that someone, somewhere has solved the obvious need for the ultimate email validation RegEx, I gave up on searching and created my own. Yes, you may have solved it too, but searching google for ‘email validation regular expression’ gives some very poor answers. Look at all the variations on RegexLib.
I do recommend reading Regular-Expressions.info’s take on email regex. They make great points about trade-offs when using the RFC spec for emails. But I’m still not happy with their ‘practical’ email regex:
[a-z0-9!#$%&'*+/=?