"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Validate Length of Numeric Input with Digits Rule in Laravel 5?

How to Validate Length of Numeric Input with Digits Rule in Laravel 5?

Published on 2024-11-08
Browse:388

How to Validate Length of Numeric Input with Digits Rule in Laravel 5?

Length Validation of Numeric Inputs in Laravel 5

When validating the length of a numeric input in Laravel 5, one might encounter issues with the size rule. Instead of checking the length of the input, it checks if the input is exactly equal to the specified size.

To address this, the digits rule should be used. According to the Laravel documentation:

$rules = [
    'national-id' => 'required|digits:10'
];

The digits rule validates that the input is a numeric value with a length equal to the specified number. In this case, the national-id field should contain 10 digits.

The numeric rule is redundant in this scenario as the digits rule already verifies if the input is numeric.

Release Statement This article is reprinted at: 1729258274 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3