When should a form field use the inputmode attribute?

Use inputmode when the field’s semantic type should remain text but a particular virtual keyboard makes entry easier. It is a keyboard hint and does not enforce validation. The input type, label and server rules still define what the value means and accepts.
Digit strings such as postal codes, account identifiers and one-time codes often use type="text" with inputmode="numeric". This preserves leading zeros and avoids number-input stepping or exponential notation. Decimal quantities can use inputmode="decimal" when locale and minus-sign requirements are tested.
<label for="verification-code">6-digit verification code</label>
<input id="verification-code" name="code" type="text" inputmode="numeric" autocomplete="one-time-code" pattern="[0-9]{6}">
Use semantic input types when they already match, such as type="email", tel, url or search. An inputmode can supplement custom editable controls, but it should not be used to disguise a field whose actual type would supply better browser behavior.
Test iOS and Android keyboards, paste, hardware input and every valid character. Some keyboards omit a minus sign or decimal separator for certain modes. If valid data cannot be entered, choose a more general keyboard and use clear validation without restricting valid input. Keep the layout rule beside the component and document why the threshold or constraint exists. This reduces accidental overrides and gives future editors a concrete condition to retest after content changes. Add this case to responsive regression tests with long content, browser zoom and at least one narrow embedded container. Record the expected wrapping and focus behavior so later component changes can be checked against a known result.