mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
New numerical validation.
This commit is contained in:
@@ -37,6 +37,8 @@ trait ValidatesAutoBudgetRequest
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$type = $data['auto_budget_type'] ?? '';
|
||||
|
||||
/** @var null|float|int|string $amount */
|
||||
$amount = array_key_exists('auto_budget_amount', $data) ? $data['auto_budget_amount'] : null;
|
||||
$period = array_key_exists('auto_budget_period', $data) ? $data['auto_budget_period'] : null;
|
||||
$currencyId = array_key_exists('auto_budget_currency_id', $data) ? (int) $data['auto_budget_currency_id'] : null;
|
||||
@@ -47,12 +49,13 @@ trait ValidatesAutoBudgetRequest
|
||||
if ('' === $type || 0 === $type) {
|
||||
return;
|
||||
}
|
||||
// TODO lots of duplicates with number validator.
|
||||
// TODO should be present at more places, stop scientific notification
|
||||
if (str_contains(strtoupper($amount), 'E')) {
|
||||
if (str_contains(strtoupper((string)$amount), 'E')) {
|
||||
$amount = '';
|
||||
}
|
||||
// basic float check:
|
||||
if (!is_numeric($amount) || '' === $amount) {
|
||||
if (!is_numeric($amount) || '' === (string) $amount) {
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget'));
|
||||
|
||||
return;
|
||||
@@ -70,8 +73,6 @@ trait ValidatesAutoBudgetRequest
|
||||
// too big amount
|
||||
if ((int) $amount > 268435456) {
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget'));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user