Email and forms: find stray characters without changing the address

Topic illustration for the article: Email and forms: find stray characters without changing the address
Practical illustration for this guide

An “invalid email” message does not prove that an invisible character is present. A form may enforce its own restrictions, the address may contain a typo, or the receiving system may not support internationalized addresses. Cleaning can diagnose a copied string, but it cannot prove that a mailbox exists or justify changing someone else's address.

Try the example in the cleaner

A reproducible diagnostic example

Compare test@example.com with test[U+200B]@example.com. The second string contains ZERO WIDTH SPACE before @. They look nearly identical but validation systems see different sequences. Highlight the string, confirm U+200B, remove it from a copy, and repeat the same validation. The example.com domain is reserved for documentation, so there is no need to send a test message.

Inspect the edges too: NBSP or an ordinary space after an address can cause rejection. Do not silently delete an internal character from an address supplied by another person. Ask the owner to copy or confirm the address again when the intended value is uncertain.

Browser validation is only one layer

The HTML Living Standard defines <input type="email">, but passing that check does not prove that a domain exists, a server accepts mail, or a mailbox was created. Client validation does not replace server validation. A site may also require a corporate domain, impose a length limit, or reject +tag addresses. Its error should state the actual rule.

Internationalized addresses need a deliberate policy. RFC 6531 defines SMTPUTF8 for non-ASCII addresses and header information. A rule that removes every non-ASCII character can corrupt valid data and can turn an address into one belonging to somebody else.

A safer sequence for users

  1. Copy the address from a trusted source instead of retyping it from memory.
  2. Inspect field edges and the position of every highlighted invisible character.
  3. Make the smallest change in a copy and retry the same form.
  4. If the error remains, read the site's rule or contact the form owner.
  5. Do not test existence through bulk mail or submit the address to unrelated services.

Guidance for form authors

Show a specific message beside the field and preserve the entered value after a failed submission. Validate on the server, set a reasonable maximum length, and avoid silent internal rewrites. If only edge whitespace is trimmed, document that behavior. When normalization changes an account identifier, show the result before final confirmation.

Logs should not retain a full address unless necessary. A diagnostic record can contain the error category, character position, and code point while masking most of the value. This reduces stored personal data while preserving enough evidence to reproduce the bug.

Different fields need different rules

A display name, email address, password, and coupon code follow different specifications. Names can contain spaces and many scripts. Email case handling needs care. Passwords must never be silently “cleaned” at login: the user expects the exact sequence they set. Give each field its own policy and test cases.

What a successful check proves

Successful client validation proves only that the string matches the syntax accepted by that form. It does not establish deliverability, ownership, or account safety. Ownership requires a separate verification flow, such as a time-limited one-time link with appropriate privacy and abuse controls.

Open the cleaner

Sources and related guides