Hello, I apologize if this is covered in another issue but to me it seems different than all those that I've been able to find.

The scenario is that I create a number field with default settings and I'd like to allow the entry of decimals without the leading zero (e.g. .5). I get the validation error message:

Number field field value must format numbers as "12,345.6789".

The value of 0.5 passes validation and the form submits. Is there a way to configure the field to allow the omission of the leading zero for values less than 1?

Thanks
Matt

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kaypro4 created an issue. See original summary.

DanChadwick’s picture

Version: 7.x-4.10 » 7.x-4.x-dev
Category: Support request » Feature request
Status: Active » Fixed
FileSize
2.29 KB

This was intentional, but I can see that it is a touch restrictive. This patch:

  1. Allows the "integer portion" of the number to be optional.
  2. Allows zero or more (rather than one or more) characters after a decimal in the "fractional portion."
  3. Doesn't allow the integer portion and fraction portion together to be empty or just a decimal point (which would now otherwise be possible).
  4. Document the regular expression in inline regex comments. These are NOT subject to normal wordwrapping coding style for clarity reasons.

This means that ".5" and "100." are now both accepted, whereas previously they would not have been.

Committed to 7.x-4.x an 8.x.

  • DanChadwick committed 20792c1 on 8.x-4.x
    Issue #2573523 by DanChadwick: Added allowing numbers starting or ending...

  • DanChadwick committed b5548f9 on
    Issue #2573523 by DanChadwick: Added allowing numbers starting or ending...
DanChadwick’s picture

Ack. Committed the code before the reg ex commenting.

Committed revision to 7.x-4.x and 8.x.

  • DanChadwick committed 1f077f6 on 8.x-4.x
    Issue #2573523 by DanChadwick: Added number validation reg ex comments.
    

  • DanChadwick committed e1c7ba3 on
    Issue #2573523 by DanChadwick: Added number validation reg ex comments.
    
kaypro4’s picture

This worked great! Thanks for the quick fix.

Matt

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.