Home  >  Article  >  Backend Development  >  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?

Susan Sarandon
Susan SarandonOriginal
2024-10-18 21:32:31933browse

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.

The above is the detailed content of How to Validate Length of Numeric Input with Digits Rule in Laravel 5?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn