메뉴
HN
Hacker News 50일 전

우리가 이메일 주소에 대해 믿는 거짓말들

IMP
7/10
핵심 요약

이메일 주소는 오래된 역사를 담고 있어 형식 검증(Validation) 규칙이 시대에 따라 미묘하게 변하고 있습니다. 복잡한 정규식(Regex)으로 이메일을 검증하는 대신, 단순한 형식 체크와 인증 이메일 발송 방식을 권장합니다. 잘못 구현된 폼 검증이 오히려 사용자의 접근을 막는 실수를 유발할 수 있기 때문입니다.

번역된 본문

Mono Font 우리가 이메일 주소에 대해 믿는 거짓말들 2026-06-06T22:54:55-04:00

TL;DR: 너무 복잡하게 생각하지 말고, 그냥 인증 이메일을 보내세요.

참아주시고 끝까지 읽어주세요. 왜냐하면 이러한 "거짓말" 중 일부는 너무 당연해 보이거나 중요하지 않은 사소한 지식처럼 느껴질 수 있기 때문입니다. 솔직히 말하면, 그것이 진실에서 그다지 멀지 않기도 합니다. 하지만 이메일 같은 평범한 것이 어떻게 우리의 예상을 깨고 놀라운 방식으로 문제를 일으킬 수 있는지, 자세하고 재미있는 예시를 들어 설명해 보겠습니다.

우리는 많은 엣지 케이스(Edge case)를 다루고, 몇 가지 장애물에 걸려 넘어지며, 기술적으로는 유효하지만 Gmail 같은 대형 시스템에서도 (아마 합당한 이유로) 일반적으로 지원되지 않는 몇 가지 사실을 발견할 것입니다. 각 예시가 여러분이 반드시 올바르게 처리해야 하는 의미 있는 사용 사례를 의미하지는 않습니다. 하지만 이 모든 것은 하나의 핵심적인 요점을 향해 점진적으로 나아가기 위한 것입니다. 이메일 주소는 오래된 역사에 얽매여 있으며, 시스템의 유효하고 무효인 구성 요소에 대한 정의는 계속해서 미묘하게 변하고 있다는 것입니다. 상식적인 결정을 내리는 것이 예상치 못한 문제를 일으키기 쉽습니다. 게다가, 경험이 많은 개발자(오래된 시스템)는 과거에는 올바랐지만 더 이상 작동하지 않는 기대를 가지고 있을 수 있습니다.

자, 더 이상 고민하지 않고 그 거짓말들에 대해 알아보겠습니다...

"이메일 주소는 그냥 정규식(Regex)으로 검증하면 돼"

가장 쉽게 따낼 수 있는 과일부터 가져와 봅시다. 저는 온라인에서 이 말을 하는 첫 번째 사람이 멀었고, 분명 마지막 사람도 아닐 것입니다. 하지만 수천 개의 블로그 게시물, 트윗, 레딧 댓글이 올라온 후에도 2026년이 된 지금도 이 안티 패턴은 끈질기게 남아 있기 때문에 이 반복은 정당화된다고 생각합니다.

정규식 접근 방식은 당신, 비즈니스, 고객에게 골칫거리를 안겨주는 세 가지 주요 경로가 있습니다:

  1. 실제 이익이 거의 없는데 비해 실행 비용이 상대적으로 높습니다.

솔직히 말하자면, 우리가 전력을 많이 소비하는 거대한 GPU 클러스터에 단순한 쿼리를 던지기 시작했던 과거에는 이 주장이 더 큰 설득력을 가졌습니다. 정규식은 어렵고, 정규식 마법사는 드물며, 정규식 엔진 구현은 일관성이 없습니다. 실수로 잘못된 결과를 내놓고도 그것을 깨닫지 못하는 경우가 매우 많습니다. 나머지 게시물을 통해 이것이 어떻게 잘못될 수 있는지 몇 가지 방법을 살펴볼 것입니다.

  1. "좋은" 정규식 중 하나를 복사해서 붙여넣기 하더라도 세상은 계속 발전합니다.

오늘날 유효한 것이 내일은 레거시가 될 수 있습니다. 인터넷에는 20년 전에는 좋았던 조언들이 널려 있습니다. 레거시는 영원하기 때문에 20년 전에 좋았던 정규식들도 널려 있습니다.

의견 주의: 입력 유효성 검사(Input validation)는 사용자가 단순한 실수를 저지르기 어렵게 만들어 사용자를 돕는 것에 더 가깝습니다. 사용자의 삶을 더 쉽게 만들어줄 만큼 제한적이어야 하지만, 딱 그 정도여야 합니다. 사용자로부터 자신을 보호하기 위해 입력 유효성 검사에 의존하지 마세요. 사용자가 스스로의 실수로부터 보호받을 수 있도록 도와주세요.

그런 의미에서 UX를 개선하기 위해 정규식 테스트를 사용하는 것은 고려해볼 만한 가치가 있는 타당한 주장입니다. UX는 중요하며 저도 그 사실을 부정하지 않습니다. 하지만 잠시 악마의 대변인이 되어보자면, 위험이 보상보다 클 수도 있다는 점을 들 수 있습니다.

주님의 해인 2026년에는 사용자가 자신의 이메일 주소를 입력하는 방법을 알거나, 더 나아가 OS, 브라우저, 키보드 앱 또는 비밀번호 관리자를 통해 자동 입력될 것이라고 합리적으로 기대할 수 있습니다. 잘못 구현된 양식 유효성 검사로 인해 서비스 이용을 거부당하는 사람들이 세심한 안내가 필요해서 거부당하는 사람들보다 더 많을 가능성이 큽니다.

그렇다면 이와 관련하여...

이메일 주소를 (정규식으로 엄격하게) 검증하지 마세요.

꼭 해야 한다면, 단순한 클라이언트 측 정규식을 사용해 사용자가 흔히 하는 실수나 오타를 피하도록 도와주세요. 가능한 한 덜 제한적으로 유지하세요. 사용자가 "something@something"을 입력했는지만 확인하는 ^[^@]+@[^@\s]+$ 같은 패턴이 좋습니다.

API나 양식 핸들러에 유효성 검사가 있다면, 프론트엔드와의 일관성을 위해 동일한 정규식을 사용하세요. 이것은 앞서 말한 "데이터베이스에서 정규식을 사용하지 마라"는 말로 거슬러 올라갑니다.

원문 보기
원문 보기 (영어)
Mono Font Lies We Tell Ourselves About Email Addresses 2026-06-06T22:54:55-04:00 TL;DR: Don't overthink it, just send a verification email. Bear with me, because some of these “lies” are going to feel obvious, or like unimportant trivia. In all honesty, that’s not that far from the truth. However, I hope you’ll let me try to build a detailed and fun illustration showing how something as mundane as email can break our expectations in surprising ways. We’ll cover a lot of edge cases, stumble over some small blocks, and even discover a few technically-correct things that are valid, but not commonly supported even in big systems like Gmail (probably for good reason, to be fair). Each example isn’t necessarily meant to be a meaningful use-case that you need to go make sure you’re handling correctly. But, all together, they’re meant to gradually build toward one main point: Email addresses are mired in old history, and the definitions of valid and invalid components of the system continue to subtly change over time. It’s easy to make a common-sense decision that is unexpectedly problematic. On top of that, older devs (and older systems) may have expectations that were correct in the past but don’t work anymore. And without further ado, on to the lies… “Email addresses can just be validated with a regex” Let’s get the low-hanging-fruit out of the way. I’m far from the first person to say this online and I certainly won’t be the last. But I feel it’s justified repetition because, even after a thousand blog posts posted, tweets twote, and reddit comments moderated, this antipattern stubbornly persists in 2026. The regex approach has three main avenues for causing heartache for you, your business, and your customers: It is relatively expensive to run, for very little-to-no real benefit To be fair, this point used to hit harder, before we started throwing simple queries at giant clusters of power-hogging GPUs. Regex is hard, regex wizardry is rare, and regex engine implementations are inconsistent. It’s very, very easy to accidentally get it wrong without realizing it. We’ll go over a couple of the ways it could go wrong through the rest of this post. Even if you copypaste one of the “good” regexes, the world is evolving. What’s valid today may be legacy tomorrow, The internet is littered with advice that was good 20 years ago. It’s also littered with regular expressions that were good 20 years ago, because legacy is forever. Opinion alert: Input validation is more about helping the user by making it harder to make simple mistakes. It should be restrictive enough to make your user’s life easier, but only just. Don’t rely on input validation to protect you from your users ; use it to protect your users from themselves. In that sense, there’s a valid argument for using regex tests to improve UX, which is worth considering. UX is important and I won’t dismiss that fact. However, to play devil’s advocate for a moment, perhaps the risk outweighs the reward. In the year of our lord 2026, you can reasonably expect your users to know how to type their own email address - or even better, auto-input from their OS, browser, keyboard app, or password manager. It’s likely that more people out there are being filtered by badly-implemented form validation than there are being filtered by their own need of hand-holding. On that note, then… Don’t validate email addresses. If you simply must , use a simple client regex to help users avoid common mistakes and typos. Try to keep it as non-restrictive as possible. Something like ^[^@]+@[^@\s]+$ , which only makes sure your user has input “something@something” If you have validation on the API or form handler, use THE SAME regex, for consistency with the frontend. This comes back to that “don’t use input validation to protect you from your users” point. By default, protect yourself by sanitizing inputs, not by rejecting them. Verify the address, don’t worry about validating it. Send an email, let your user click a verification link or input a verification code. That’s it. It doesn’t need to be more complicated than that. You don’t need to check the domain’s MX record; your email service does this as part of the whole “sending the email” thing (Also, spoiler alert, but there’s some more MX Record fun below). And you definitely don’t need to do a big regex. In fact you’re probably already sending a verification email anyway! If you are, this might be an excuse to delete code , which is every programmer’s actual favorite thing! Now with the easy part out of the way, let’s go over some of the specific points that make email handling fun and confusing! “An email address needs to be valid, and email providers support any valid addresses” This may shock you, but the Internet is made of software. And if there’s any universal through-line on software, it’s the fact that it very frequently diverges from your expectations. Email server software, from big providers like Gmail to open-source projects like Postfix , have varying levels of support for the official rules of email formats. Postfix only added support for SMTPUTF8 around 2015 but it wasn’t enabled by default until years layer. Dovecot , on the other hand, still doesn’t support it in 2026. This isn’t limited to open-source; Gmail puts restrictions on allowed characters when creating an address, but it does appear to support sending with UTF8. We’ll dive into SMTPUTF8 and RFC 6531 a bit more in a later section. But let’s look at another example, where we can go explicitly against the restrictions of every relevant RFC . Let’s look at RFC 5321 Section 4.5.3 , which defines length limits. 4.5.3.1.1. Local-part The maximum total length of a user name or other local-part is 64 octets. That’s a pretty simple restriction, and thankfully easy to understand! But there are some terms that might be unfamiliar for some readers: “local-part.” Simply put, the local-part is everything that comes before the @ character. (Let’s keep it that simple for this example, but we’ll come back to the local-part for some other parts of the article) octet An octet is a standard 8-bit byte ( Wikipedia ) So now, the email address entirelytoomanycharactersinthisemailwhatisevenhappeningblahblahdonttrythisathome@gitpush–force.com , which has an 80-byte local-part, is 100% unambiguously invalid. So naturally it doesn’t work. Yeah, remember that thing about software diverging from expectations? You can actually send email to me at that address. Your provider will (probably) allow it without complaining, my provider will happily deliver it to my inbox. “An email address can only have ASCII characters” This belief will probably be more commonly held in the English-speaking world, but I’m curious: If you’re not in the Anglosphere, do you still expect emails to require ASCII latin characters? Back in 2012, which is simultaneously recent and ancient in the world of tech, Email Internationalization became a thing through a set of RFCs corresponding to different parts of the email stack. For email addresses specifically, RFC 6531 defines the SMTPUTF8 extension, which allows for non-ASCII characters in the local-part of an email address. In that sense, it’s actually pretty surprising that so much of the world’s population wasn’t able to put their own name, in its native written form, in an email address until just 14 years ago. International characters were technically working and allowed even before 2012, under things like Punycode through RFC 3490 , something of an encoding hack where unicode chara