mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-12-12 02:00:47 +01:00
27 lines
596 B
PHP
27 lines
596 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Rules;
|
||
|
|
||
|
use Closure;
|
||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||
|
|
||
|
class IsValidRegex implements ValidationRule
|
||
|
{
|
||
|
/**
|
||
|
* Run the validation rule.
|
||
|
*/
|
||
|
public function validate(string $attribute, mixed $value, Closure $fail) : void
|
||
|
{
|
||
|
try {
|
||
|
preg_match('/' . $value . '/', '');
|
||
|
|
||
|
if (preg_last_error() !== PREG_NO_ERROR) {
|
||
|
$fail('validation.IsValidRegex')->translate();
|
||
|
}
|
||
|
}
|
||
|
catch (\Throwable $ex) {
|
||
|
$fail('validation.IsValidRegex')->translate();
|
||
|
}
|
||
|
}
|
||
|
}
|