coolrist / role-based-email-validator
Laravel custom rule to detect role-based emails.
Package info
github.com/coolrist/laravel-role-based-email-validator
pkg:composer/coolrist/role-based-email-validator
Requires
- php: ^8.0
- laravel/framework: ^11.0|^12.0
README
The Coolrist/RoleBasedEmailValidator package is a Laravel extension that adds a custom validation rule to block role-based email addresses like admin@, info@, support@, etc. It ensures users register with personal email addresses, improving the reliability of your user data and the effectiveness of your communication.
1. Why Use This Package?
In many applications, it's important to make sure each user is uniquely identifiable. This package helps you:
- โ Improve user data quality โ no more generic emails in your database.
- ๐ซ Reduce spam and abuse โ role-based addresses are commonly used for testing or fraudulent signups.
- ๐ฌ Enable targeted communication โ youโre messaging a real person, not a shared inbox.
2. Installation
Install it via Composer:
composer require coolrist/role-based-email-validator
Then, publish the configuration file (optional but recommended):
php artisan vendor:publish --tag=coolrist-role-based-config
This creates a config/role_based.php file where you can tweak settings to fit your use case.
3. Configuration
Hereโs what the config file looks like:
return [ 'only_custom' => false, // Leave false to use the built-in list + your custom list 'list' => [ // Add your own role-based email prefixes here 'compta', 'direction', // Common ones like 'admin', 'support' are already covered internally ], ];
only_custom => false: combines the internal list (included in the package) with your custom list. Best for full protection.only_custom => true: disables the internal list and uses only your custom entries.
The internal list already includes common role-based prefixes like admin, support, info, sales, and more.
4. Usage
Once installed and configured, you can use the not_role_based rule in your Laravel validators:
Validator::make($request->all(), [ 'email' => 'required|email|not_role_based|unique:users,email', // <-- Add the rule here ]);
If a user tries to register with something like admin@example.com, validation will fail and return:
"The email address is role-based."
๐ก This message is customizable in your Laravel language files.
5. Bonus: Rock-Solid Email Validation ๐ก๏ธ
For even stronger email checks, combine this package with Propaganistas/Laravel-Disposable-Email, which blocks temporary email addresses.
Install it:
composer require propaganistas/laravel-disposable-email
Then chain the rules like so:
'email' => 'required|email:strict,dns,spoof|indisposable|not_role_based',
๐ฅ With this combo, you ensure the email is technically valid, not disposable, and not role-based. Only solid, permanent, personal emails get through.
6. Want to Help Us Push This Like a TUF Laptop with an RTX? ๐๐ฎ
If you want to support the project โ with some code, some cash, or just good vibes โ reach out! The maintainer's email is in the composer.json file, like a hidden bonus in a well-coded level. ๐
We love stylish commits, fresh ideas, and even dream-desk setup gifs (especially with RGB lighting). Thanks for being here โ whether you're a dev, supporter, or just a curious visitor stopping by with good energy. ๐ป๐ฅ