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.
Comment | File | Size | Author |
---|---|---|---|
#3 | 2809103-3.patch | 1.14 KB | chishah92 |
|
Comments
Comment #2
chishah92 CreditAttribution: chishah92 at Blisstering Solutions commentedComment #3
chishah92 CreditAttribution: chishah92 at Blisstering Solutions commentedAdded the working regex
Thanks!
~Chirag
Comment #4
Pawlus CreditAttribution: Pawlus commentedIsn'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
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, '/') . '?') : '';
.Comment #5
DanChadwick CreditAttribution: DanChadwick commentedCheck 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.