Skip to content

Validator overview

Create validators through Rule rather than calling constructors directly. Every page in this section contains its public construction method and a working example.

Rule methodValidatorBest for
string()StringValidatorText and labels
boolean()BooleanValidatorStrict booleans
number()NumberValidatorNumeric values and ranges
integer()IntegerValidatorStrict integers
decimal()DecimalValidatorStrict floats
email()EmailValidatorEmail addresses
phoneNumber()PhoneNumberValidatorPhone numbers
password()PasswordValidatorPassword strength
dateTime()DateTimeValidatorDates and times
url()UrlValidatorURLs
uuid()UuidValidatorUUID strings
ipAddress()IpAddressValidatorIPv4 and IPv6
regex()RegexValidatorCustom formats
array() / arrayOf()ArrayValidatorArrays and per-item rules
enum()EnumValidatorEnum values and instances
file()FileValidatorGeneral uploads
image()ImageValidatorOne image upload
images()ImagesValidatorMultiple image uploads
object()ObjectValidatorNested DTOs
objectArray()ObjectArrayValidatorArrays of DTOs
username()UsernameValidatorUsernames and uniqueness
use Fynix\Rule;
$validator = Rule::string('displayName')
->label('Display name')
->length(2, 80)
->in(['Alice', 'Bob']);
$first = $validator->validateField('A');
$all = $validator->validateFieldAll('A');

Shared methods include label(), required(), optional(), in(), notIn(), sameAs(), differentFrom(), conditional requiredness, and prohibited-field constraints. Fluent methods are immutable and return new validator instances.

Use withoutGenericValidation() when a specialized validator must bypass the shared requiredness, HTML, and length layer. File and array validators manage their own structure checks.