Non-numeric number field input is not validated

Created on 3 July 2025, 6 days ago

Problem/Motivation

If a non-numeric string is entered in a number field, the browser sends a blank value to the server, which means that the is_numeric check in Number::validateNumber() never runs, so the user never sees the "%name must be a number." validation error and the form is allowed to submit without a value.

No value is saved to the number field.

This was originally reported in the farmOS GitHub issue queue here: https://github.com/farmOS/farmOS/issues/983

Steps to reproduce

  • Create a number field on a node.
  • Set a breakpoint on this return statement: https://git.drupalcode.org/project/drupal/-/blob/60627bbd140b814fd3bfd20...
  • Enter a non-numeric value (eg: "a") and save the node.
  • Observe that the breakpoint pauses execution on the return statement because the value is empty, indicating that the browser passed an empty value to the server.
  • Observe that no validation message was displayed, and no value was saved to the node.

Proposed resolution

??

Remaining tasks

??

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

TBD

🐛 Bug report
Status

Active

Version

11.2 🔥

Component

field system

Created by

🇺🇸United States m.stenta

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @m.stenta
  • 🇺🇸United States m.stenta
  • 🇳🇿New Zealand quietone

    In Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies .

  • 🇮🇳India ankusht1515 Mumbai

    @m.stenta When I create a field of type 'number', it doesn't allow alphabetic characters to be entered, except for the letter 'e', which is interpreted as part of an exponential value. However, if the value includes 'e', submitting the node still results in a validation error. Even tried with some numbers line 2-4 still it give valid number validations

Production build 0.71.5 2024