StringValidator
StringValidator
Section titled “StringValidator”Use StringValidator for names, titles, descriptions, and other text values.
Create a rule
Section titled “Create a rule”Rule::string(string $field): StringValidatorThe name is used in messages. The property name is the key used in the DTO and returned errors.
Methods
Section titled “Methods”| Method | Description |
|---|---|
| `min(int | float $value)` |
| `max(int | float $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. |
Example
Section titled “Example”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.