Skip to content
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

[9.x] feature: min_digits and max_digits validation #43797

Merged
merged 5 commits into from
Aug 21, 2022
Merged

[9.x] feature: min_digits and max_digits validation #43797

merged 5 commits into from
Aug 21, 2022

Conversation

danharrin
Copy link
Contributor

As per the size rule, the number of digits in numeric input cannot be validated traditionally using min and max.

Currently, we have, digits to validate the exact length of a number, and digits_between to validate the length within two boundaries.

However, as far as I can see there is not yet a way to validate that a number has a minimum OR maximum number of digits, just both.

This PR introduces two validation rules - min_digits and max_digits for this use:

Validator::validate([
    'number' => 1000,
], [
    'number' => [
        'min_digits:3', 'max_digits:5', // Passes as `1000` has 4 digits
        'min:3', 'max:5', // Fails as `1000` is greater than 5
    ],
])

@danharrin
Copy link
Contributor Author

The failing 8.1 test is unrelated and needs rerunning.

@taylorotwell taylorotwell merged commit b8db0d2 into laravel:9.x Aug 21, 2022
@danharrin
Copy link
Contributor Author

danharrin commented Aug 21, 2022

Hey @taylorotwell do you need laravel/laravel and laravel/docs PRs for this or are you handling that?

Doesn't look like anything has been pushed or PRed, so:

laravel/laravel#5975 laravel/docs#8148

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