anonaddy/app/Rules/ValidRegex.php
2024-08-01 17:12:13 +01:00

21 lines
518 B
PHP

<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class ValidRegex implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (@preg_match("/{$value}/", '') === false) {
$fail("{$attribute} is an invalid regular expression.");
}
}
}