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
{
private $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
*
* @return bool
*/
public function passes($attribute, $email): bool
{
$v = Validator::make(['email' => $email], ['email' => 'required|email']);
if ($v->fails()) {
$this->message = \trans('validation.emailinvalid');
return false;
}
list($local, $domain) = explode('@', $email);
// don't allow @localhost and other no-fqdn
if (strpos($domain, '.') === false) {
$this->message = \trans('validation.emailinvalid');
return false;
}
return true;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message(): ?string
{
return $this->message;
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Apr 24, 10:25 AM (1 d, 9 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
83/dc/51af067b6bc91e8b68e3179d749a
Default Alt Text
ExternalEmail.php (1 KB)

Event Timeline