Email validation not working properly in laravel
Asked Answered
S

3

6

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

$request->validate([
   'email'=>'required|email',
]);
Sawfish answered 9/10, 2019 at 7:5 Comment(4)
I'd really recommend reading the docs at laravel's official website linkMoonfish
Your code is correct. That's exactly what the documentation suggests. This is not the part that is not working properly.Spay
if a client does not give .com (at the end of email id) he/she will face an validation error.I want this validation also but can't get itSawfish
emails don't have to end with .comSumatra
S
13

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.

Seise answered 31/12, 2020 at 0:45 Comment(0)
J
2

You can add the following to the email validation: email:rfc,dns. According to the docs, the default is rfc, which accepts emails without domain, so the dns rule is adding the domain check.

With the example it looks like this:

$request->validate([
    'email'=>'required|email:rfc,dns',
]);
Jilli answered 5/12, 2022 at 11:3 Comment(0)
M
0

use this:

$rules = [
  'email' => 'required|email'
 ];
$validator = Validator::make($request->all(), $rules);
        if (!$validator->fails()) {
}
Medellin answered 9/10, 2019 at 9:8 Comment(1)
if a client does not give .com (at the end of email id) he/she will face an validation error.I want this validation also but can't get itSawfish

© 2022 - 2024 — McMap. All rights reserved.