26 lines
576 B
PHP
26 lines
576 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
class ValidDomain implements ValidationRule
|
|
{
|
|
/**
|
|
* Indicates whether the rule should be implicit.
|
|
*
|
|
* @var bool
|
|
*/
|
|
public $implicit = true;
|
|
|
|
/**
|
|
* Run the validation rule.
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
if (! preg_match('/(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)/', $value)) {
|
|
$fail('Invalid domain name.');
|
|
}
|
|
}
|
|
}
|