Email normalization and format validation.
Provides consistent email handling for authentication operations. All emails are normalized before storage or comparison to prevent duplicate accounts and ensure reliable matching.
Normalization Steps
- Trim leading/trailing whitespace
- Downcase the entire email
- Apply Unicode NFKC normalization
NFKC is applied to emails per Unicode best practices. It is intentionally NOT applied to passwords (per NIST SP 800-63B).
Format Validation
Uses a permissive regex (~r/^[^\s]+@[^\s]+$/) to avoid rejecting
valid addresses. Maximum length is 160 characters.
Gmail dot-stripping and plus-stripping are NOT applied per design decision D-41 -- users should be able to use plus-addressing.
Summary
Functions
Normalizes an email address by trimming, downcasing, and applying NFKC.
Validates the format of an email address.
Functions
Normalizes an email address by trimming, downcasing, and applying NFKC.
Examples
iex> Sigra.Email.normalize(" FOO@Bar.COM ")
"foo@bar.com"
iex> Sigra.Email.normalize("user+tag@example.com")
"user+tag@example.com"
Validates the format of an email address.
Returns :ok for valid emails or {:error, reason} for invalid ones.
Validation rules:
- Must contain exactly one
@with non-empty local and domain parts - Must not contain whitespace
- Must not exceed 160 characters
Examples
iex> Sigra.Email.validate_format("user@example.com")
:ok
iex> Sigra.Email.validate_format("no-at-sign")
{:error, "must contain exactly one @ sign"}