LengthRule
extends BaseRule
in package
Checks the length of a string is within an allowed range.
Important:
- Comparisons are done using multi-byte strings.
- The range is inclusive:
min <= len <= max - Default min is 0.
- Default max is infinite (PHP_INT_MAX).
Table of Contents
Properties
Methods
- fields() : array<string|int, string>
- What fields are registered for this rule?
- getFieldValues() : array<string|int, mixed>
- Get a list of values that match this rule's fields.
- getName() : string
- The shorthand name for this rule.
- isEmpty() : bool
- Is this data field empty?
- parse() : void
- Parse a ruleset.
- validate() : void
- Validate data against this rule.
- validateOne() : void
- Validate a single value against this rule.
Properties
$fields
public
array<string|int, string>
$fields
= []
$max
public
int
$max
= PHP_INT_MAX
$min
public
int
$min
= 0
Methods
fields()
What fields are registered for this rule?
public
fields() : array<string|int, string>
Tags
Return values
array<string|int, string>getFieldValues()
Get a list of values that match this rule's fields.
public
getFieldValues(array<string|int, mixed>|object $data) : array<string|int, mixed>
Parameters
- $data : array<string|int, mixed>|object
Return values
array<string|int, mixed>getName()
The shorthand name for this rule.
public
static getName() : string
Tags
Return values
stringisEmpty()
Is this data field empty?
public
static isEmpty(array<string|int, mixed>|ArrayAccess $data, string $field) : bool
Note, this considers a numeric 'zero' as non-empty.
Parameters
- $data : array<string|int, mixed>|ArrayAccess
- $field : string
Return values
boolparse()
Parse a ruleset.
public
parse(array<string|int, mixed> $ruleset) : void
Parameters
- $ruleset : array<string|int, mixed>
Tags
validate()
Validate data against this rule.
public
validate(array<string|int, mixed>|object $data) : void
Parameters
- $data : array<string|int, mixed>|object
Tags
validateOne()
Validate a single value against this rule.
public
validateOne(string $field, mixed $value) : void
Parameters
- $field : string
- $value : mixed