FormValidation
extends CI_Form_validation
in package
Extended form validation class.
Provides additional validation rules beyond CodeIgniter's built-in form validation. Includes validation for datetime, hostname, IP address, email, file paths, etc.
Usage:
$this->form_validation
->set_data(['email' => 'user@example.com', 'port' => '8080'])
->set_rules('email', 'Email', 'required|email')
->set_rules('port', 'Port', 'required|port');
Table of Contents
Methods
- __construct() : mixed
- Initialize form validation.
- datetime() : bool
- Validate datetime format.
- email() : bool
- Validate email address format.
- hostname() : bool
- Validate hostname format.
- hostname_or_ipaddress() : bool
- Validate hostname or IP address format.
- ipaddress() : bool
- Validate IP address format.
- ipaddress_or_cidr() : bool
- Validate IP address or CIDR notation format.
- is_path() : bool
- Validate file or directory path format.
- port() : bool
- Validate port number (1-65535).
- unix_username() : bool
- Validate UNIX username format.
Methods
__construct()
Initialize form validation.
public
__construct([array<string|int, mixed> $rules = [] ]) : mixed
Parameters
- $rules : array<string|int, mixed> = []
-
Initial validation rules. Default is empty array.
datetime()
Validate datetime format.
public
datetime(string $value, string $format) : bool
Parameters
- $value : string
-
Input value to validate.
- $format : string
-
Expected date format (PHP date format string).
Tags
Return values
bool —True if valid, false otherwise.
email()
Validate email address format.
public
email(string $value) : bool
Uses the regular expression from the HTML5 specification for validation.
Parameters
- $value : string
-
Input value to validate.
Tags
Return values
bool —True if valid email address, false otherwise.
hostname()
Validate hostname format.
public
hostname(string $value) : bool
Parameters
- $value : string
-
Input value to validate.
Return values
bool —True if valid hostname, false otherwise.
hostname_or_ipaddress()
Validate hostname or IP address format.
public
hostname_or_ipaddress(string $value) : bool
Parameters
- $value : string
-
Input value to validate.
Return values
bool —True if valid hostname or IP address, false otherwise.
ipaddress()
Validate IP address format.
public
ipaddress(string $value) : bool
Parameters
- $value : string
-
Input value to validate.
Return values
bool —True if valid IP address, false otherwise.
ipaddress_or_cidr()
Validate IP address or CIDR notation format.
public
ipaddress_or_cidr(string $value) : bool
Parameters
- $value : string
-
Input value to validate.
Return values
bool —True if valid IP address or CIDR, false otherwise.
is_path()
Validate file or directory path format.
public
is_path(string $value[, mixed $denyLeadingSlash = false ]) : bool
Parameters
- $value : string
-
Input value to validate.
- $denyLeadingSlash : mixed = false
-
Deny leading slashes if true. Default is false.
Return values
bool —True if valid path, false otherwise.
port()
Validate port number (1-65535).
public
port(string $value) : bool
Parameters
- $value : string
-
Input value to validate.
Return values
bool —True if valid port number, false otherwise.
unix_username()
Validate UNIX username format.
public
unix_username(string $value) : bool
Parameters
- $value : string
-
Input value to validate.
Return values
bool —True if valid UNIX username, false otherwise.