FRM-014b Put a string of digits that is not a quantity in a text input, never a number input
- Level
- Guideline, our choice
- Verdict
- Insufficient evidence (1 of 3 judges spoke)
- Area
- Forms
- Status
- proposed, version 1.0.0
Rule
Put a string of digits that is not a quantity, such as a one-time code, a card number, an account number, a phone number or a postcode, in a text input: type="text", or type="tel" for a phone number. Never put it in type="number".
Examples
Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.
Don't: Codes and numbers in a number input
Don't: The spinner hidden, the field still a number input
Do: Digit strings in text inputs
inputMode="numeric". The arrow keys and the scroll wheel change nothing, spaces are allowed, and the value is checked as text, so the leading zero stays.Do: A true small count may be a number input
Why
A number input treats its value as a quantity that goes up and down in steps. A code or a card number never does: nobody wants the next card number. The browser's number handling then works against the value, in the ways listed under Our reasons. No WCAG criterion requires this.
Our reasons
Fewer than two judges have spoken about which input a string of digits belongs in, so the verdict is Insufficient evidence (1 of 3 judges spoke) and this guideline is our choice. Carbon supports it. So do GOV.UK and NN/g, expert witnesses who do not vote. Material and Apple are silent, which is not a vote against. We keep such values out of a number input for four reasons.
- The value changes on its own. A leading zero can vanish once the value is read as a number, so "04718" becomes 4718. A long card number can be shown in exponent form or lose its last digits.
- What people type is refused or let through wrongly. Spaces and dashes are refused,
maxLengthis ignored, while "e", plus and minus are let through. - Errors cannot be explained. A value the browser cannot read comes back empty, so the form cannot tell the person what was wrong.
- The value moves by accident. The arrow keys, and in some browsers the scroll wheel over a focused field, change the value when the person meant to move on.
Do
- On a gym's payment page, Card number, Security code and Membership number are text inputs, with the
autocompletevalues from FRM-007. Check each value as a string, for example withz.string().regex(/^\d{10}$/)on the value with spaces removed, as the guideline FRM-017a describes, so leading zeros stay. - Get the digit keypad from
inputMode="numeric", as FRM-014a describes, not from the number type. - Mobile number is
type="tel", as FRM-014 says, and keeps the spaces and the plus sign the person typed. - A one-time code on sign-in is a text input, so a pasted "482 913" goes in and the spaces can be stripped; FRM-008 covers the paste.
- Turn the browser's own check off with
noValidate, as FRM-007 says, and show errors as FRM-002a and FRM-002b describe. - A true small count may use a number input with step controls. On a café's booking form, Tables starts at 1 and is seldom more than three, so
<Input type="number" min={1} />is allowed. This guideline does not require it. - Our own advice, beyond this guideline: where people type an exact amount across a wide range, a text input with
inputMode="decimal"(FRM-014a) is often the better choice.
Don't
- Use
<Input type="number">for Membership number to get the keypad. "0471826390" can come back as 471826390. - Hide the spinner on a number input with
[appearance:textfield]and call it a text field. The arrow keys and the scroll wheel still change the value. - Read a code with
valueAsNumberorz.coerce.number(), which throws away its leading zeros. - Give Postcode
type="number", which refuses a postcode with a space or a letter. In a country where every postcode is digits only, it is still a text input, withinputMode="numeric"from FRM-014a.
Exceptions
- Quantities. Counts, amounts, prices, years and ages are outside this guideline. It takes no side on quantities.
- The keypad and the keyboard. Which keypad a digit field shows is FRM-014a; email, phone and web address types are FRM-014.
- Purpose. The
autocompletevalues for card, code, phone and postcode fields are FRM-007. - A product that chooses otherwise. This is a guideline. A product that keeps a number input for such a value still checks it as a string and shows errors as FRM-002a asks.
Verdict
Insufficient evidence (1 of 3 judges spoke). Only the judges decide; the expert witnesses are shown but do not vote. The judges do not settle this one, so it is a guideline: our own choice, with our reasons above. How verdicts work
| Source | Role | Stance | Page |
|---|---|---|---|
| WCAG 2.2 | Law | – No criterion applies | |
| Material Design | Judge | No position | |
| Apple Human Interface Guidelines | Judge | No position | |
| Carbon Design System | Judge | Supports | Number input: usage |
| GOV.UK Design System | Expert witness | Supports | Text input |
| Nielsen Norman Group | Expert witness | Supports | Design Guidelines for Input Steppers, by Yuxuan (Tammy) Zhou |
Each stance links to the page it rests on, read on the date in the source register. This page never repeats what a source says; read the source itself.
History
- Version 1.0.0, : First version.
Last checked against the other rules for conflicts on .
More in Forms: 15 rules and 12 guidelines · All rules
Justified is an independent project. It is not affiliated with, sponsored or endorsed by the organisations whose guidance it cites. Read the full statement.
Apple is a trademark of Apple Inc., registered in the U.S. and other countries and regions.