Home  >  Article  >  Backend Development  >  How to Validate Numeric Input Length Effectively in Laravel 5?

How to Validate Numeric Input Length Effectively in Laravel 5?

Barbara Streisand
Barbara StreisandOriginal
2024-10-18 21:30:31984browse

How to Validate Numeric Input Length Effectively in Laravel 5?

Validating Numeric Input Length in Laravel 5

To specify the expected length of a numeric input in Laravel 5, the initial approach using 'size' validation rule may not suffice. Instead, you can employ the 'digits' rule as follows:

foo.blade.php:

<input type="text" name="national-id" />

FooController.php:

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

The 'digits' rule ensures that the provided input contains the specified number of digits. In this case, it verifies that the 'national-id' field contains 10 digits, without requiring an exact match. Additionally, the 'required' rule ensures that the field is not empty before performing the length validation.

By using the 'digits' rule, you can effectively validate the length of numeric inputs in your Laravel 5 applications.

The above is the detailed content of How to Validate Numeric Input Length Effectively 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