Laravel package for email validation using the UserCheck API.
MIT License
A Laravel package for validating email addresses using the UserCheck.com API.
Install the package via Composer:
composer require usercheck/usercheck-laravel
Add your UserCheck API key to your .env
file:
USERCHECK_API_KEY=your_api_key_here
You can obtain a free API key by signing up at https://app.usercheck.com/register.
Use the usercheck
rule in your Laravel validation:
$request->validate([
'email' => 'required|email|usercheck'
]);
By default, the usercheck
rule will only validate the email address's syntax using the UserCheck API. If the email is invalid, the validation will fail.
The usercheck
rule accepts several parameters:
block_disposable
: Fails validation if the email is from a disposable email providerblock_no_mx
: Fails validation if the domain has no MX recordsblock_public_domain
: Fails validation for public email domains (e.g., Gmail, Yahoo). Great to prevent users from signing up with their personal email addresses.domain_only
: Validates only the domain part of the email. Great for privacy; only the domain will be sent to the API.You can combine these options to create a custom validation rule.
$request->validate([
'email' => 'required|email|usercheck:domain_only,block_disposable,block_no_mx',
]);
You can also use the UserCheck facade directly:
use UserCheck\Laravel\Facades\UserCheck;
$result = UserCheck::validateEmail('[email protected]');
$result = UserCheck::validateDomain('example.com');
Both methods return an array with is_valid
and error_code
keys.
The package includes English translations by default. To customize the error messages, publish the language files:
php artisan vendor:publish --provider="UserCheck\Laravel\UserCheckProvider" --tag="lang"
Then, edit the files in resources/lang/vendor/usercheck
.
Run the tests with:
composer test
Contributions are welcome! Please see CONTRIBUTING.md for details.
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
For support, please email [email protected] or open an issue on GitHub.