PHPackages                             littleskinchina/laravel-email-username-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. littleskinchina/laravel-email-username-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

littleskinchina/laravel-email-username-validator
================================================

Domain-specific validation for email local-part (username) in Laravel.

v1.0.3(1mo ago)04MITPHPPHP &gt;=8.1

Since Jan 16Pushed 1mo agoCompare

[ Source](https://github.com/LittleSkinChina/laravel-email-username-validator)[ Packagist](https://packagist.org/packages/littleskinchina/laravel-email-username-validator)[ RSS](/packages/littleskinchina-laravel-email-username-validator/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (5)Used By (0)

Laravel Email Username Validator
================================

[](#laravel-email-username-validator)

Domain-specific validation for email local-part (username) in Laravel. App developers register validator classes that declare their applicable domains, and the package plugs into Laravel's `Validator` via a simple `email_username` rule.

Might be useful to reduce hard-bounced emails caused by invalid email addresses entered by user, might not.

90% codes (including this README) are generated by GitHub Copilot. Use at your own risk. PRs welcome.

Install
-------

[](#install)

```
composer require littleskinchina/laravel-email-username-validator
```

Publish the config:

```
php artisan vendor:publish --tag=config --provider="LittleSkin\\LaravelEmailUsernameValidator\\EmailUsernameValidatorServiceProvider"
```

Configure
---------

[](#configure)

Edit `config/email-username-validator.php` and list your rule classes:

```
return [
    'rules' => [
        App\EmailUsernameRules\GmailRule::class,
        App\EmailUsernameRules\OutlookRule::class,
    ],
    // More config options available, see comments on config file for details
];
```

A rule class must implement `LittleSkin\\LaravelEmailUsernameValidator\\Contracts\\EmailUsernameRule`:

```
use LittleSkin\LaravelEmailUsernameValidator\Contracts\EmailUsernameRule;

class ExampleRule implements EmailUsernameRule
{
    // Domains this rule applies to, exact or wildcard
    public static function domains(): array
    {
        return [
            'example.com',
            '*.example.com',
        ];
    }

    public function passes(string $username, string $domain, array $parameters = []): bool
    {
        // Example: require at least 6 chars length
        return strlen($username) >= 6;
    }
}
```

A single rule can cover multiple domains via its `domains()` return value.

You can also implement `EmailUsernameRuleWithMessage` to provide rule-specific failure messages:

```
class ExampleRuleWithMessage extends ExampleRule implements EmailUsernameRuleWithMessage {
    public function message(): string
    {
        return 'The email address is invalid.';
    }
}
```

### Predefined rules

[](#predefined-rules)

The package includes some predefined rules for common email providers under namespace `LittleSkin\LaravelEmailUsernameValidator\Rules`. See `src/Rules` for details.

Some predefined rules might be too relaxed or too strict. Feel free to modify or create your own rules as needed.

Again, PRs are welcome.

Use in validation
-----------------

[](#use-in-validation)

Suggested to use with Laravel's built-in `email` rule, which validates overall email format and DNS records.

```
$request->validate([
    'email' => ['required', 'email:strict,dns', 'email_username'],
]);
```

Semantics:

- Each domain resolves to at most one rule (the first concrete match wins, otherwise the first wildcard match).
- If no rules match a domain, behavior is controlled by `unknown-domain-pass`.

### Customizing messages and localization

[](#customizing-messages-and-localization)

- Implement `EmailUsernameRuleWithMessage` to provide a rule-specific failure message. That message wins over config/localization.
- Otherwise the package uses the `'messages'` config entry, resolved via Laravel's translator if it matches a translation key.
- Default translations ship under the namespace `email-username`, or you can point to your own key or literal.
- The `:attribute` and `:domain` placeholders will be replaced automatically by the Validator replacer.

Copyright
---------

[](#copyright)

Copyright (c) 2026-present Suzhou Honoka Techonology Co., Ltd.

Licensed under MIT.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance93

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~44 days

Total

4

Last Release

36d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0fd215c5f05553230c05a9ea89cb2df719169b1f10cf2513c56994de19a74cb0?d=identicon)[tnqzh123](/maintainers/tnqzh123)

---

Top Contributors

[![tnqzh123](https://avatars.githubusercontent.com/u/16630630?v=4)](https://github.com/tnqzh123 "tnqzh123 (10 commits)")

### Embed Badge

![Health badge](/badges/littleskinchina-laravel-email-username-validator/health.svg)

```
[![Health](https://phpackages.com/badges/littleskinchina-laravel-email-username-validator/health.svg)](https://phpackages.com/packages/littleskinchina-laravel-email-username-validator)
```

###  Alternatives

[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[propaganistas/laravel-disposable-email

Disposable email validator

6023.0M7](/packages/propaganistas-laravel-disposable-email)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.8M75](/packages/spatie-laravel-honeypot)[illuminate/validation

The Illuminate Validation package.

18838.2M1.7k](/packages/illuminate-validation)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M199](/packages/laravel-ai)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
