In Laravel, you can validate email addresses using the email validation rule. Here’s an example of how to validate an email address in Laravel:
use Illuminate\Http\Request;
public function validateEmail(Request $request)
{
$request->validate([
'email' => 'required|email',
]);
}
In this example, we’re validating an email address submitted through a form using Laravel’s validate method. The email validation rule ensures that the input is a valid email address.
You can also customize the error message that’s displayed when the validation fails by adding a message parameter to the validate method:
$request->validate([
'email' => 'required|email',
], [
'email.required' => 'Please enter an email address.',
'email.email' => 'Please enter a valid email address.',
]);
In this example, we’re customizing the error messages for the required and email rules for the email field.
Note: Laravel’s email validation rule only checks if the input is in a valid email format. It does not check if the email address actually exists or if the email can be delivered to the recipient.
