Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Validation Email address

I have created an edit form in my Laravel application form which accepts an email address. I have used Laravel validation on the server-side. It is validating the email address correctly when I pass a clearly invalid value like 'xxxxxx'.

But the problem is when I send an email address with only a top level domain and no dot like 'xxxxxx@yyyyyy', it accepts it as a valid email address.

How can I validate the email address to ensure it's using a proper domain?

like image 695
amit rawat Avatar asked Nov 06 '19 08:11

amit rawat


People also ask

How can I check email is valid in laravel?

You can check if an email is valid or not in Laravel using the validate method by passing in the validation rules. You can validate your email addresses using one or more of the validation rules we have discussed. Or as previously demonstrated, you can write your own custom validation method.

How can I check if an email address is valid in PHP?

PHP - Validate E-mail The easiest and safest way to check whether an email address is well-formed is to use PHP's filter_var() function.

What is the validator used to validate email address?

Regex, or regular expression, is a string of characters that is used to describe a search pattern. A regular expression can be used to validate the format of an email address.


2 Answers

With Laravel 7: you can use

'email' => 'email:rfc,dns'
like image 194
jasme Avatar answered Oct 25 '22 05:10

jasme


You can simply do:

$validator = Validator::make($request->all(), [
        'Email'=>'required|email'
    ]);

like image 22
Anil Stha Avatar answered Oct 25 '22 04:10

Anil Stha