DEV Community 👩‍💻👨‍💻

Morcos Gad
Morcos Gad

Posted on

New Feature Laravel min_digits and max_digits Validation

In the new version 9.26 we have the feature min_digits and max_digits validation

According to the size rule, the number of digits in a digital input cannot be traditionally validated 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 bounds.

However, as far as I can see, there is still no way to verify that a number has a minimum or maximum number of digits, just both.

This PR offers two validation rules - min_digits and max_digits for this usage

https://github.com/laravel/framework/pull/43797

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

I hope you enjoyed with me and to learn more about this release visit the sources and search more. I adore you who search for everything new.

Source :- https://laravel-news.com/laravel-9-26-0
Source :- https://www.youtube.com/watch?v=ZCYqn0Y6qc0

Top comments (1)

Collapse
 
thetnaingtun3 profile image
Thet Naing Tun

Great. Thanks!

What image format should you use in your next project? 🤔