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?
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.
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.
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.
With Laravel 7: you can use
'email' => 'email:rfc,dns'
You can simply do:
$validator = Validator::make($request->all(), [
'Email'=>'required|email'
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With