use Illuminate\Support\Facades\Validator; $rules = ['email' => 'required|email']; $userData = ['email' => 'example@example.com']; $validator = Validator::make($userData, $rules); if ($validator->fails()) { echo "Invalid Email Address"; } else { echo "Valid Email Address"; }
use Illuminate\Support\Facades\Validator; $rules = ['date' => 'required|date']; $userData = ['date' => '2021-08-06']; $validator = Validator::make($userData, $rules); if ($validator->fails()) { echo "Invalid Date"; } else { echo "Valid Date"; }In the code examples above, we use the PHP Validator package library to validate input data. We create validation rules and the input values to validate against. The `Validator::make` method creates a new instance of the validator, and if it fails the validation, the `fails()` method returns `true`. We can use this to handle the errors or move on to the next step in the code. The package library used in the example is the Laravel Validator package, which provides a set of validation rules that can be used in any PHP project.