Whenever it comes time to validate an email address, I always end up going through the same exact process.
I start with a simple regular expression- for example, this:
(.+)@[\w]+\.[a-zA-Z]+
It works great for a majority of email addresses- however, it’s not perfect. It lets through a lot of invalid email addresses. For example, “.name@something.a” is considered a valid email address by this regular expression. So, let’s take a few steps to correct this:
([-a-zA-Z0-9])([-.a-zA-Z0-9])*@[\w]+\.[a-zA-Z]{2,5}
A bit better, right? But what about valid email addresses, such as john+smith@mail.something.com and $A12345@example.mobile? Same goes for the seemingly invalid email addresses such as “Abc\@def”@example.com. But, alas, these are all valid.