Skip to content

StringValidator

Use StringValidator for names, titles, descriptions, and other text values.

Rule::string(string $field): StringValidator

The name is used in messages. The property name is the key used in the DTO and returned errors.

MethodDescription
`min(intfloat $value)`
`max(intfloat $value)`
length(int $min, int $max)Set both length limits.
required(bool $required = true)Mark the field as required.
optional()Allow null or an empty value.
validateField(mixed $value)Return the first error or null.
validateFieldAll(mixed $value)Return every applicable error.
use Fynix\Rule;
$validator = Rule::string('displayName')
->length(2, 60)
->required();
$error = $validator->validateField('A');

String validation rejects non-string values, HTML tag content, and values outside the configured range. See the validator overview for inherited methods and error behavior.