New numerical validation.

This commit is contained in:
James Cole
2024-01-02 14:33:17 +01:00
parent 85bde79fd1
commit 102da7b21e
32 changed files with 276 additions and 50 deletions

View File

@@ -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;
}
}
}