Skip to content
Validates email addresses belong to the given domain
Branch: master
Clone or download

Laravel Email Domain Validation

Validation rule for Laravel 5.5 to validate that a given email address belongs to the provided domain.

Wildcard domains and multiple domains are supported.

Basic Usage

If your class implements the Laravel ValidatesRequests trait you can validate a simple domain as follows.

use Jtn\EmailDomain;

$this->validate(request()->all(), [
    'email' => ['email', new EmailDomain('')]

This validation rule will only pass if the email provided is

Wildcard Usage

$this->validate(request()->all(), [
    'email' => ['email', new EmailDomain('*')]

This rule wil match any of,, etc. To match the rule must be new EmailDomain('*.*').

Match Multiple Domains

To match multiple domains simply pass an array of accepted domains to the constructor. You can pass any number of domains and wildcards as an array to check them all.

$this->validate(request()->all(), [
    'email' => [
        new EmailDomain(['', ''])

Strict Mode

Strict mode can be disabled to match wildcard domains. This is useful if you would like to match all subdomains under

The following example will match domains and any length of subdomains under it.

$domainRule = new EmailDomain(['', ['*']]);
$this->validate(request()->all(), [
    'email' => ['email', $domainRule->nonStrict()]



  • Add support for strict matching


  • Initial release, support for simple domains and wildcard
You can’t perform that action at this time.