Oihana PHP System

ISO8601DateRule extends Rule

Validates whether a given value is a valid ISO 8601 date or datetime expression.

This rule uses a comprehensive regular expression to match ISO 8601 formats, including date-only, week date, ordinal date, and datetime with timezone offsets.

✅ Supported examples:

2025-10-13
2025-10-13T18:25:43Z
2025-10-13T18:25:43+02:00
2025-286T23:59:59.999Z
2025-W41-1

❌ Invalid examples:

13/10/2025
2025-13-40
2025-10-13 99:99
Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

DEFAULT_PATTERN  = '/^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/'
The default pattern regexp expression of the rule.

Properties

$message  : string
The message pattern if the rule is not valid.
$pattern  : string
The regular expression pattern used for validation.

Methods

__construct()  : mixed
Constructor.
check()  : bool
Check if the value is valid.

Constants

DEFAULT_PATTERN

The default pattern regexp expression of the rule.

public mixed DEFAULT_PATTERN = '/^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/'

Properties

$message

The message pattern if the rule is not valid.

protected string $message = "The :attribute is not a valid ISO8601 date expression."

$pattern

The regular expression pattern used for validation.

protected string $pattern

Methods

__construct()

Constructor.

public __construct([string|null $pattern = null ][, string|null $message = null ]) : mixed
Parameters
$pattern : string|null = null

Optional custom pattern.

$message : string|null = null

Optional custom error message.

check()

Check if the value is valid.

public check(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

        
On this page

Search results