When is a number not `input type='number'`?

When it “only consist[s] of numbers but isn’t strictly speaking a number”. See Why the GOV.UK Design System team changed the input type for numbers for more details.

While Drupal supports #pattern on FormAPI elements, there’s no top-level property for #inputmode. That can be added via #attributes, like:

$form['textfield'] = array(
  '#type' => 'textfield',
  '#title' => 'Any number of digits',
  '#pattern' => '[0-9]*',
  '#attributes' => [
    'inputmode' => 'numeric',
  ],
);