Normalize an email address for comparison
Trim whitespace and lowercase only the domain, preserving the local part.
function normalizeEmail(address) { const value = address.trim(); const at = value.lastIndexOf('@'); return `${value.slice(0, at)}@${value.slice(at + 1).toLowerCase()}`; }
Input & expected output
Input
" Ana.Silva@Example.COM "Expected output
"Ana.Silva@example.com"The edge case
Input
"ANA@EXAMPLE.COM"Expected output
"ANA@example.com"Know the limits
- The local part is kept as typed: its case rules belong to the receiving server.
- Provider-specific rules such as ignored dots or +tags are not applied. Do not merge accounts on this alone.
The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.
Source & maintenance
Written by Oveyon for this edition of 1loc.dev; it is not part of the original collection. Copyright (c) 2026 Oveyon. MIT licensed.
Its file in the public edition: contents/normalize-an-email-address.mdx in akamind/1loc, commit 0a77f131b22d. The function above is the implementation the lab runs and the tests exercise; the test suite checks that it is the code that file carries. Read the license.
Keep exploring
- Convert an email domain to punycode — Keep the local part and convert an international domain to its ASCII xn-- form.
- Get the domain of an email address — Take the part after the last @ and lowercase it, for domain checks and grouping.
- Mask an email address for logs — Keep the first character and the domain; hide the rest of the local part.