Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel validation rule for email

Tags:

php

laravel

I have no idea how to make validation rules for email field not accepting email free account like gmail, yahoo etc. Can anyone guide me on this topic. Thanks in advance

like image 769
Er. Mukesh Sharma Avatar asked Jan 25 '18 09:01

Er. Mukesh Sharma


People also ask

How can I check email is valid in laravel?

Laravel provides validation rules to validate input fields. 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.

What is bail in laravel validation?

you can easily use bail validation in laravel 6, laravel 7, laravel 8 and laravel 9. If you added more then one validation on your field like required, integer, min and max then if first is fail then other should stop to display error message. right now by default it print other too.


1 Answers

Put a list of email providers into a config file, for example into the config/email.php:

'banned_email_providers' => '@gmail\.com|@yahoo\.com'

Then use the regex validation rule using this list:

'email' => ['regex:/^((?!' . config('email.banned_email_providers') . ').)*$/'],
like image 64
Alexey Mezenin Avatar answered Sep 27 '22 19:09

Alexey Mezenin