Notes

The resilient input

15 October 2026 3 min read

Strict fields reject what people really type. Pick an amount, a phone number, an email or a name and watch two fields read the same text.

  • Forms
  • Resilience
  • Accessibility

Every input field is a small contract. You promise to understand what a person types, and they promise to type it the way you expected. They never read the contract.

What people actually type

Checks the text as typed

Strict field

Waiting for input

Works out what was meant

Resilient field

Waiting for input

Attributes for this field: inputmode="decimal"

Live demo. Everything runs in your browser. Now try to break it.
ResilientInput.svelte, 187 lines

Choose a field, then press the examples one by one. Both panels read the exact same text. The left one checks it as typed. The right one works out what was meant.

What breaks on the left

  • Amounts. parseFloat("1.299,50") is 1.299, and parseFloat("12,5") is 12. Nothing fails. The wrong number goes through quietly, which is worse than an error.
  • Phone numbers. +49 171 2345678, 0171/2345678 and (0171) 234 5678 are the same number. A pattern for ten digits accepts none of them.
  • Emails. A trailing space from a paste, a capital letter in the domain, a + in the name or an umlaut in the domain: all valid, all rejected by a lowercase-only pattern.
  • Names. [A-Za-z ] rejects Zoë, Nguyễn, Björk and 李雷. It also rejects the person who is typing.

None of these are exotic. They are what the first week of real users looks like.

What the right one does

It normalises instead of rejecting. Strip spaces, dashes and brackets from a phone number. Trim an email and lowercase the domain. Collapse double spaces in a name. Do the work the person would otherwise have to do.

It shows what it understood. "We will call +49 171 2345678" is a confirmation the person can check in half a second. If the guess was wrong, they can see it before it costs anything.

It says when it assumed something. A number that starts with 0 gets +49. The note under the result says so.

It keeps the raw text. Format for display, but never overwrite what the person typed while they are still typing. Moving their cursor is a small betrayal.

It validates late and explains the fix. Check on blur or on submit, not on every keystroke. A red message after the first character tells the person off for not being finished yet. "An email needs an @ and a domain" tells them what to do.

Amounts are the dangerous one

1.299 is one thousand two hundred ninety-nine in Germany and one point two nine nine in the US. The rule in the demo is small: if there is one separator followed by exactly three digits, it is a thousands separator. Otherwise the last separator is the decimal point.

const sep = Math.max(s.lastIndexOf('.'), s.lastIndexOf(','));
const digitsAfter = s.length - sep - 1;
const sepCount = (s.match(/[.,]/g) ?? []).length;

if (sepCount === 1 && digitsAfter === 3) return Number(s.replace(/[.,]/g, ''));
return Number(s.slice(0, sep).replace(/[.,]/g, '') + '.' + s.slice(sep + 1));

It is still a guess, which is why the result line says what it read. For money, show the guess before you send it.

Let the browser do half of it

The cheapest resilience is the attributes. They cost nothing and they decide which keyboard opens and what the browser can fill in.

<input type="email" autocomplete="email" inputmode="email" autocapitalize="off" spellcheck="false" />
<input type="tel" autocomplete="tel" />
<input inputmode="decimal" />
<input autocomplete="name" />

Use inputmode="decimal" for amounts and not type="number". A number input rejects separators, drops leading zeros and scrolls its value with the mouse wheel. Never use it for phone numbers, postcodes or card numbers: they are strings of digits, not quantities. And never block paste.

Keep an impossible user

Like the product card, the field needs a fixture. Keep a list of ugly inputs and run every field against it: a pasted value with a non-breaking space, a number with the other country's separators, a name with an apostrophe, a name with one letter, a name in another script, an emoji. If the field only passes with [email protected], it is not finished.

Related

How bright was it?

Five lamps and an optional line. Feedback, a bug, an idea, anything. I read every one and sum them up once a month.

Pick a lamp

Stored without name, address or cookie, and deleted after a year. Details in the privacy notice.