Email validation not working properly in laravel

Viewed 3189

I want to validate email. Suppose if a customer give an email address like "demo@gmail" it gives an validation error. Email should be "demo@gmail.com".What is the code to do this validation.I do it but not working properly.My code in below:

$request->validate([
   'email'=>'required|email',
]);
2 Answers

The comments under the question are correct, BUT...

If you are looking for email validator with domain at the end, you can use this filter:

'email' => 'email:filter'

It uses the filter_var() method to check if the email is valid. Refer to https://laravel.com/docs/6.x/validation#rule-email for other email validation types.

use this:

$rules = [
  'email' => 'required|email'
 ];
$validator = Validator::make($request->all(), $rules);
        if (!$validator->fails()) {
}
Related