CodeIgniter v4.5 API

Rules
in package

Validation Rules.

Tags
see
RulesTest

Table of Contents

Properties

$nonStrictRules  : Rules

Methods

__construct()  : mixed
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.

Properties

$nonStrictRules read-only

private Rules $nonStrictRules

Methods

__construct()

public __construct() : mixed

differs()

The value does not match another field in $data.

public differs(array<string|int, mixed>|bool|float|int|object|string|null $str, string $otherField, array<string|int, mixed> $data[, string|null $error = null ][, string|null $field = null ]) : bool
Parameters
$str : array<string|int, mixed>|bool|float|int|object|string|null
$otherField : string
$data : array<string|int, mixed>

Other field/value pairs

$error : string|null = null
$field : string|null = null
Return values
bool

equals()

Equals the static value provided.

public equals(array<string|int, mixed>|bool|float|int|object|string|null $str, string $val) : bool
Parameters
$str : array<string|int, mixed>|bool|float|int|object|string|null
$val : string
Return values
bool

exact_length()

Returns true if $str is $val characters long.

public exact_length(array<string|int, mixed>|bool|float|int|object|string|null $str, string $val) : bool

$val = "5" (one) | "5,8,12" (multiple values)

Parameters
$str : array<string|int, mixed>|bool|float|int|object|string|null
$val : string
Return values
bool

field_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
bool

greater_than()

Greater than

public greater_than(array<string|int, mixed>|bool|float|int|object|string|null $str, string $min) : bool
Parameters
$str : array<string|int, mixed>|bool|float|int|object|string|null

expects int|string

$min : string
Return values
bool

greater_than_equal_to()

Equal to or Greater than

public greater_than_equal_to(array<string|int, mixed>|bool|float|int|object|string|null $str, string $min) : bool
Parameters
$str : array<string|int, mixed>|bool|float|int|object|string|null

expects int|string

$min : string
Return values
bool

in_list()

Value should be within an array of values

public in_list(array<string|int, mixed>|bool|float|int|object|string|null $value, string $list) : bool
Parameters
$value : array<string|int, mixed>|bool|float|int|object|string|null
$list : string
Return values
bool

is_not_unique()

Checks the database to see if the given value exist.

public is_not_unique(array<string|int, mixed>|bool|float|int|object|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 : array<string|int, mixed>|bool|float|int|object|string|null
$field : string
$data : array<string|int, mixed>
Return values
bool

is_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(array<string|int, mixed>|bool|float|int|object|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 : array<string|int, mixed>|bool|float|int|object|string|null
$field : string
$data : array<string|int, mixed>
Return values
bool

less_than()

Less than

public less_than(array<string|int, mixed>|bool|float|int|object|string|null $str, string $max) : bool
Parameters
$str : array<string|int, mixed>|bool|float|int|object|string|null

expects int|string

$max : string
Return values
bool

less_than_equal_to()

Equal to or Less than

public less_than_equal_to(array<string|int, mixed>|bool|float|int|object|string|null $str, string $max) : bool
Parameters
$str : array<string|int, mixed>|bool|float|int|object|string|null

expects int|string

$max : string
Return values
bool

matches()

Matches the value of another field in $data.

public matches(array<string|int, mixed>|bool|float|int|object|string|null $str, string $otherField, array<string|int, mixed> $data[, string|null $error = null ][, string|null $field = null ]) : bool
Parameters
$str : array<string|int, mixed>|bool|float|int|object|string|null
$otherField : string
$data : array<string|int, mixed>

Other field/value pairs

$error : string|null = null
$field : string|null = null
Return values
bool

max_length()

Returns true if $str is $val or fewer characters in length.

public max_length(array<string|int, mixed>|bool|float|int|object|string|null $str, string $val) : bool
Parameters
$str : array<string|int, mixed>|bool|float|int|object|string|null
$val : string
Return values
bool

min_length()

Returns true if $str is at least $val length.

public min_length(array<string|int, mixed>|bool|float|int|object|string|null $str, string $val) : bool
Parameters
$str : array<string|int, mixed>|bool|float|int|object|string|null
$val : string
Return values
bool

not_equals()

Does not equal the static value provided.

public not_equals(array<string|int, mixed>|bool|float|int|object|string|null $str, string $val) : bool
Parameters
$str : array<string|int, mixed>|bool|float|int|object|string|null
$val : string
Return values
bool

not_in_list()

Value should not be within an array of values.

public not_in_list(array<string|int, mixed>|bool|float|int|object|string|null $value, string $list) : bool
Parameters
$value : array<string|int, mixed>|bool|float|int|object|string|null
$list : string
Return values
bool

required()

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
bool

required_with()

The field is required when any of the other required fields are present in the data.

public required_with([array<string|int, mixed>|bool|float|int|object|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 : array<string|int, mixed>|bool|float|int|object|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
bool

required_without()

The field is required when all the other fields are present in the data but not required.

public required_without([array<string|int, mixed>|bool|float|int|object|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 : array<string|int, mixed>|bool|float|int|object|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.

Return values
bool

        
On this page

Search results