Laravel built-in functions ease all types of validations and so for numbers, digits, and integers. Let’s look at the use of the validate function in Laravel, to define rules for validation of numbers.
public function validate_data(Request $request)
{
$num_validate = $request->validate([
phone_number=> 'required|numeric|min:10'
]);
}
The function above defines rules to validate a phone number in Laravel. The validate function can be called in a Controller function and it validates data before sending it to a database or any other file.
We can define validation rules as per our specifications or the types of numbers used. For example, while using numbers for measurements with a specified min and max value. The validation rule as shown below can be used.
$rules = ['Fno' => 'numeric|min:2|max:5', 'Lno' => 'numeric|min:2'];