Skip to content

Add FILTER_VALIDATE_STRLEN for UTF-8 string length validation #21428

@masakielastic

Description

@masakielastic

Description

I would like to propose a new filter validator FILTER_VALIDATE_STRLEN that validates the length of a UTF-8 string.

The length is counted in Unicode code points. Grapheme clusters are not considered.

The validator supports min_len and max_len options and does not depend on the mbstring extension.

A prototype implementation is provided in the accompanying pull request.

$options = [
    'options' => [
        'max_len' => 2,
        'default' => 'error',
    ],
];

var_dump(
    filter_var('🐘🐘🐘', FILTER_VALIDATE_STRLEN, $options)
);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions