I've created decimal number field in my webform. I have set decimal delimeter as '.' and thousands separator as ' ' (space). After submission validation I got following PHP warning:
preg_match(): Compilation failed: webform_number_format_match() line 831 in webform/components/number.inc

That line is
return preg_match("/^-?\ ?(?!\.?$)(?:\d{1,3}(?:$thousands\d{2,3})*)?(?:$decimal\d*)?$/x", $value);
It turns out that when thousands separator is set to space, it doesn't get escaped by preg_quote.

As a result I got following regex:
/^-?\ ?(?!\.?$)(?:\d{1,3}(?: ?\d{2,3})*)?(?:\.\d*)?$/x
This regex returns following error:
? The preceding token is not quantifiable

When I esceped the offending space like so
/^-?\ ?(?!\.?$)(?:\d{1,3}(?:\ ?\d{2,3})*)?(?:\.\d*)?$/x
the warning disappeared.

CommentFileSizeAuthor
#3 2809103-3.patch1.14 KBchishah92

Comments

Pawlus created an issue. See original summary.

chishah92’s picture

Assigned: Unassigned » chishah92
chishah92’s picture

Status: Active » Needs review
StatusFileSize
new1.14 KB

Added the working regex

Thanks!
~Chirag

pawlus’s picture

Status: Needs review » Active

Isn't that patch correct only in my specific case? It doesn't test for thousands and decimal separator, instead it just assumes that decimal delimeter is a period. Thousands separator can be a comma, a period, a space or nothing. Decimal delimeter can be a period or a comma. If I were to use the patch you provided, that automatically sets regex to /^-?\ ?(?!\.?$)(?:\d{1,3}(?:\d{2,3})*)?(?:\.\d*)?$/x , and then defined a comma as either separator, it would fail to validate properly my input (for example 23,4 wouldn't pass). I think something like adding

if($thousands == ' ?') {
    $thousands = "\ ?";
  }

before aforementioned preg_match would be more appropriate solution, or maybe incorporating it into if statement in this line
812 $thousands = $separator ? (preg_quote($separator, '/') . '?') : '';.

danchadwick’s picture

Status: Active » Needs work
Issue tags: -Decimal numbers, -field validation, -regex

Check the latest dev. I seem to recall this being fixed, but a quick search didn't find the issue. Also you patch removes the functionality, rather than fixes it.

liam morland’s picture

Version: 7.x-4.12 » 7.x-4.x-dev
Status: Needs work » Closed (outdated)

Drupal 7 is no longer supported. If this applies to a supported version, please re-open.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.