Validating user input is one of the most important parts of application development. There are various types of integer validations as stated in the validation rules list in our previous tutorial. There are different types of float values. The larger ones (8 bytes) are often referred to as double data type and the (4 bytes) floating point values. Let’s see what validation rules best fit each of thee types.
We can define Laravel validation rules in the Controller class. The rules check values before saving or storing user data in the application and database. Validation rules can be applied to many types of inputs from a user.
There are separate rules for mobile numbers, maximum character validations, and image and video uploads. For example, checking image dimensions. Let’s check the rule to validate different types of float.
Validation rule for different types of float
We should use the numeric validation rule for float validation.
For example, as shown below.
$request->validate([
'float-number' => 'numeric',
]);
The rule above checks if the. number. entered supports float value inputs.
However, we can also use the regex patterns for float values that have decimal points. For example prices under a certain format. We can use the regular expression as shown below.
$rules = array(
'price_value' => 'regex:/^\d*(\.\d{2})?$/'
);
The rules above can be applied to all different types of float values.