Michael Long
1 min readMar 10, 2020

--

Please do NOT use regex to “validate” email addresses. You’re almost certainly guaranteed to get it wrong, as the RFC’s for what constitutes a “valid” email address are extremely complex.

I’ve lost track of the number of times I’ve had a site’s validation system reject a perfectly valid email address.

The expression given misses many valid characters, doesn’t understand quoted local email parts, comments, or ip address for domains.

A regular expression can only act as a rudimentary filter. The problem with regular expressions is that telling someone that their perfectly valid e-mail address is invalid (a false positive) because your regular expression can’t handle it is just rude and impolite from the user’s perspective.

Not to mention the fact that you probably also just lost a customer.

For more, see:

https://stackoverflow.com/questions/2049502/what-characters-are-allowed-in-an-email-address#2049510

https://stackoverflow.com/questions/201323/how-to-validate-an-email-address-using-a-regular-expression

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (1)