Skip to content

[12.x] Allows for strict numeric validation #56328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2025

Conversation

peterfox
Copy link
Contributor

Changes

  • Changes the validateNumeric in ValidatesAttributes trait to accept a strict parameter.
  • Updated uses of validateNumeric in other validation methods to provide the new parameter.
  • Adds a test for the change.

Why

Same purpose as #56313. This would allow for blocking strings being used in JSON requests for numbers e.g. allow 1 but not '1'. This is useful for APIs where allowing strings might not be what the end user wants compared to web forms that are more flexible when it comes to strings.

$v = new Validator($trans, ['foo' => '1'], ['foo' => 'Numeric:strict']); // fails
$v = new Validator($trans, ['foo' => 1], ['foo' => 'Numeric:strict']); // passes

Notes

I've kept this to just numeric as that will work with both floats and integers rather than applying this parameter to the wide range of number based options.

@taylorotwell taylorotwell merged commit f866540 into laravel:12.x Jul 18, 2025
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants