Files
timebank-cc-public/app/Rules/MaxLengthWithoutHtml.php
Ronald Huynen 2547717edb Initial commit
2026-03-23 21:37:59 +01:00

35 lines
859 B
PHP

<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class MaxLengthWithoutHtml implements ValidationRule
{
/**
* The maximum length allowed for the stripped text.
*/
protected int $maxLength;
/**
* Create a new rule instance.
*/
public function __construct(int $maxLength)
{
$this->maxLength = $maxLength;
}
/**
* Run the validation rule.
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$strippedText = strip_tags($value ?? '');
$currentLength = strlen($strippedText);
if ($currentLength > $this->maxLength) {
$fail("The {$attribute} field must not exceed {$this->maxLength} characters (HTML tags excluded). Currently {$currentLength} characters.");
}
}
}