Filter
in package
Static utility class for filtering and normalizing string inputs.
The Filter class provides methods to clean and normalize string inputs into standard formats. Unlike Parse and Validate classes, these methods return null if the input cannot be processed rather than throwing exceptions or returning false. This class is used by Parse methods to clean inputs before validation.
Table of Contents
Methods
- currency() : string|null
- Filters and normalizes a currency string.
- date() : string|null
- Filters and normalizes a date string to YYYY-MM-DD format.
- dateTime() : string|null
- Filters and normalizes a date-time string to YYYY-MM-DD HH:MM:SS format.
- time() : string|null
- Filters and normalizes a time string to HH:MM:SS format.
Methods
currency()
Filters and normalizes a currency string.
public
static currency(string $i_st) : string|null
Removes commas, handles dollar signs, negative signs, and parentheses for negative amounts. Returns a normalized numeric string or null if invalid.
Examples:
- "$1,234.56" → "1234.56"
- "($1.23)" → "-1.23"
- "-$5.00" → "-5.00"
Parameters
- $i_st : string
-
The currency string to filter
Return values
string|null —The normalized currency string, or null if invalid
date()
Filters and normalizes a date string to YYYY-MM-DD format.
public
static date(string $i_st) : string|null
Accepts various date formats and converts them to the standard ISO 8601 date format (YYYY-MM-DD).
Parameters
- $i_st : string
-
The date string to filter
Return values
string|null —The normalized date string in YYYY-MM-DD format, or null if invalid
dateTime()
Filters and normalizes a date-time string to YYYY-MM-DD HH:MM:SS format.
public
static dateTime(string $i_st) : string|null
Accepts various date-time formats and converts them to the standard format (YYYY-MM-DD HH:MM:SS) in GMT timezone.
Parameters
- $i_st : string
-
The date-time string to filter
Return values
string|null —The normalized date-time string, or null if invalid
time()
Filters and normalizes a time string to HH:MM:SS format.
public
static time(string $i_st) : string|null
Accepts various time formats and converts them to the standard 24-hour format (HH:MM:SS).
Parameters
- $i_st : string
-
The time string to filter
Return values
string|null —The normalized time string in HH:MM:SS format, or null if invalid