Page MenuHomePhorge

ExternalEmail.php
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

ExternalEmail.php

<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\Validator;
class ExternalEmail implements Rule
{
protected $message;
/**
* Determine if the validation rule passes.
*
* Email address validation with some more strict rules
* than the default Laravel's 'email' rule
*
* @param string $attribute Attribute name
* @param mixed $email Email address input
*/
public function passes($attribute, $email): bool
{
$v = Validator::make(['email' => $email], ['email' => 'required|email:strict']);
if ($v->fails()) {
$this->message = \trans('validation.emailinvalid');
return false;
}
[$local, $domain] = explode('@', $email);
// don't allow @localhost and other no-fqdn
if (!str_contains($domain, '.')) {
$this->message = \trans('validation.emailinvalid');
return false;
}
// don't allow IPv6 addresses in the domain part
if (str_contains($domain, ':')) {
$this->message = \trans('validation.emailinvalid');
return false;
}
// don't allow IPv4 addresses in the domain part
if (preg_match('/^[0-9.]+$/', $domain)) {
$this->message = \trans('validation.emailinvalid');
return false;
}
return true;
}
/**
* Get the validation error message.
*/
public function message(): ?string
{
return $this->message;
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Apr 24, 10:18 AM (1 h, 20 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18741501
Default Alt Text
ExternalEmail.php (1 KB)

Event Timeline