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

How to Validate Numeric Input Length Effectively in Laravel 5?

Barbara Streisand
Release: 2024-10-18 21:30:31
Original
1101 people have browsed it

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" />
Copy after login

FooController.php:

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

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!

source:php
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template