Rules
in package
Validation Rules.
Tags
Table of Contents
Methods
- differs() : bool
- The value does not match another field in $data.
- equals() : bool
- Equals the static value provided.
- exact_length() : bool
- Returns true if $str is $val characters long.
- field_exists() : bool
- The field exists in $data.
- greater_than() : bool
- Greater than
- greater_than_equal_to() : bool
- Equal to or Greater than
- in_list() : bool
- Value should be within an array of values
- is_not_unique() : bool
- Checks the database to see if the given value exist.
- is_unique() : bool
- Checks the database to see if the given value is unique. Can ignore a single record by field/value to make it useful during record updates.
- less_than() : bool
- Less than
- less_than_equal_to() : bool
- Equal to or Less than
- matches() : bool
- Matches the value of another field in $data.
- max_length() : bool
- Returns true if $str is $val or fewer characters in length.
- min_length() : bool
- Returns true if $str is at least $val length.
- not_equals() : bool
- Does not equal the static value provided.
- not_in_list() : bool
- Value should not be within an array of values.
- required() : bool
- required_with() : bool
- The field is required when any of the other required fields are present in the data.
- required_without() : bool
- The field is required when all the other fields are present in the data but not required.
Methods
differs()
The value does not match another field in $data.
public
differs(string|null $str, string $field, array<string|int, mixed> $data) : bool
Parameters
- $str : string|null
- $field : string
- $data : array<string|int, mixed>
-
Other field/value pairs
Return values
boolequals()
Equals the static value provided.
public
equals(string|null $str, string $val) : bool
Parameters
- $str : string|null
- $val : string
Return values
boolexact_length()
Returns true if $str is $val characters long.
public
exact_length(string|null $str, string $val) : bool
$val = "5" (one) | "5,8,12" (multiple values)
Parameters
- $str : string|null
- $val : string
Return values
boolfield_exists()
The field exists in $data.
public
field_exists([array<string|int, mixed>|bool|float|int|object|string|null $value = null ][, string|null $param = null ][, array<string|int, mixed> $data = [] ][, string|null $error = null ][, string|null $field = null ]) : bool
Parameters
- $value : array<string|int, mixed>|bool|float|int|object|string|null = null
-
The field value.
- $param : string|null = null
-
The rule's parameter.
- $data : array<string|int, mixed> = []
-
The data to be validated.
- $error : string|null = null
- $field : string|null = null
-
The field name.
Return values
boolgreater_than()
Greater than
public
greater_than(string|null $str, string $min) : bool
Parameters
- $str : string|null
- $min : string
Return values
boolgreater_than_equal_to()
Equal to or Greater than
public
greater_than_equal_to(string|null $str, string $min) : bool
Parameters
- $str : string|null
- $min : string
Return values
boolin_list()
Value should be within an array of values
public
in_list(string|null $value, string $list) : bool
Parameters
- $value : string|null
- $list : string
Return values
boolis_not_unique()
Checks the database to see if the given value exist.
public
is_not_unique(string|null $str, string $field, array<string|int, mixed> $data) : bool
Can ignore records by field/value to filter (currently accept only one filter).
Example: is_not_unique[table.field,where_field,where_value] is_not_unique[menu.id,active,1]
Parameters
- $str : string|null
- $field : string
- $data : array<string|int, mixed>
Return values
boolis_unique()
Checks the database to see if the given value is unique. Can ignore a single record by field/value to make it useful during record updates.
public
is_unique(string|null $str, string $field, array<string|int, mixed> $data) : bool
Example: is_unique[table.field,ignore_field,ignore_value] is_unique[users.email,id,5]
Parameters
- $str : string|null
- $field : string
- $data : array<string|int, mixed>
Return values
boolless_than()
Less than
public
less_than(string|null $str, string $max) : bool
Parameters
- $str : string|null
- $max : string
Return values
boolless_than_equal_to()
Equal to or Less than
public
less_than_equal_to(string|null $str, string $max) : bool
Parameters
- $str : string|null
- $max : string
Return values
boolmatches()
Matches the value of another field in $data.
public
matches(string|null $str, string $field, array<string|int, mixed> $data) : bool
Parameters
- $str : string|null
- $field : string
- $data : array<string|int, mixed>
-
Other field/value pairs
Return values
boolmax_length()
Returns true if $str is $val or fewer characters in length.
public
max_length(string|null $str, string $val) : bool
Parameters
- $str : string|null
- $val : string
Return values
boolmin_length()
Returns true if $str is at least $val length.
public
min_length(string|null $str, string $val) : bool
Parameters
- $str : string|null
- $val : string
Return values
boolnot_equals()
Does not equal the static value provided.
public
not_equals(string|null $str, string $val) : bool
Parameters
- $str : string|null
- $val : string
Return values
boolnot_in_list()
Value should not be within an array of values.
public
not_in_list(string|null $value, string $list) : bool
Parameters
- $value : string|null
- $list : string
Return values
boolrequired()
public
required([array<string|int, mixed>|bool|float|int|object|string|null $str = null ]) : bool
Parameters
- $str : array<string|int, mixed>|bool|float|int|object|string|null = null
Return values
boolrequired_with()
The field is required when any of the other required fields are present in the data.
public
required_with([string|null $str = null ][, string|null $fields = null ][, array<string|int, mixed> $data = [] ]) : bool
Example (field is required when the password field is present):
required_with[password]
Parameters
- $str : string|null = null
- $fields : string|null = null
-
List of fields that we should check if present
- $data : array<string|int, mixed> = []
-
Complete list of fields from the form
Return values
boolrequired_without()
The field is required when all the other fields are present in the data but not required.
public
required_without([string|null $str = null ][, string|null $otherFields = null ][, array<string|int, mixed> $data = [] ][, string|null $error = null ][, string|null $field = null ]) : bool
Example (field is required when the id or email field is missing):
required_without[id,email]
Parameters
- $str : string|null = null
- $otherFields : string|null = null
-
The param fields of required_without[].
- $data : array<string|int, mixed> = []
- $error : string|null = null
- $field : string|null = null
-
This rule param fields aren't present, this field is required.