Validate email input that it's not blacklisted for a specific domain name.
Add blacklist
to the validation rules string.
public function store(Request $request) {
$this->validate($request,
['email' => 'required|email|blacklist']
);
}
Require this package with composer:
composer require alariva/laravel-email-domain-blacklist
This package uses AutoDiscovery.
If you are using Laravel <= 5.4 manually add the Service Provider to the providers array in config/app.php
Alariva\EmailDomainBlacklist\EmailDomainBlacklistServiceProvider::class,
Publish the package config:
php artisan vendor:publish --provider="Alariva\EmailDomainBlacklist\EmailDomainBlacklistServiceProvider" --tag=config
Laravel Email Domain Blacklist is a lightweight package that extends your validation rules with blacklist
.
You may pass a local or remote JSON file containing all the blacklisted email domains, usually those that are disposable email services.
In case you are using a third-party remote list you may also append your custom email domains.
You may update the cached list with the console command (manually or scheduled).
An auto-update option is available in case you don't want to run the command and prefer to auto-update on the first validation taking place.
The validation message is translated into english and spanish, feel free to PR your language.
public function store(Request $request) {
$this->validate($request,
['email' => 'required|email|blacklist']
);
}
You may specify the preferred URL or file path to update the blacklist.
Keep null
if you don't want to use a remote source.
Default: https://raw.githubusercontent.com/ivolo/disposable-email-domains/master/index.json
You may change the cache key for the sourced blacklist.
Keep null
if you want to use the default value.
Specify if should automatically get source when cache is empty.
ADVICE: This may slow down the first request upon validation.
Default: false
You may use a string of pipe |
separated domains list.
Keep null
if you don't want to append custom domains.
Example: example.com|example.net|foobar.com
.
Manually updating the cached blacklist:
php artisan blacklist:update-email-domains
It's OK if you run this command after a deploy and refresh on a weekly/monthly basis.
Scheduling the cached blacklist update (example):
// app/Console/Kernel.php @schedule
// ...
$schedule->command('blacklist:update-email-domains')
->monthly()
->sundays()
->at('05:00')
->withoutOverlapping()
->sendOutputTo(storage_path('logs/email-domains-blacklist.txt'));
// ...
Simply add the JSON translation key to your main project translations, and this will override the package validation message.
More info on overriding translation
vendor/bin/phpunit
I built this package to off-load some code in my application Fimedi NET, a clinical nutrition control app for dietitians and patients.
Please try to follow the psr-2 coding style guide. http://www.php-fig.org/psr/psr-2/
This package was inspired on this great post by Matt Kingshott
- Ariel Vallese
- Ilya Volodarsky for maintenance of disposable email domains repo
- At symbol icon made by Gregor Cresnar from www.flaticon.com