1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-23 14:56:51 +02:00

Update FieldtypeInteger so that it will still convert to integer even if number prefixed with USD or EUR symbol.

This commit is contained in:
Ryan Cramer
2018-03-22 07:46:02 -04:00
parent 89ed62a6d8
commit 3e6840748b

View File

@@ -54,8 +54,13 @@ class FieldtypeInteger extends Fieldtype {
if(is_string($value) && strlen($value) && !ctype_digit(ltrim($value, '-'))) {
// string value with one or more non-digit characters
$value = trim($value);
// trim off common currency symbols
$value = trim($value, '$€ ');
if(preg_match('/^(\de\d|0x\d+|\+\d+)/', $value)) {
if(ctype_digit("$value")) {
// trimming reduced it to an int
} else if(preg_match('/^(\de\d|0x\d+|\+\d+)/', $value)) {
// likely a valid number, but in a non-native format to PW
// examples: 1e123213, 0x1234, +123 (intval handles these)
$value = intval($value);