Skip to content

enhancement: Add regex parameter #145

Description

@Androlax2

Hello,

I came with an idea, maybe it could be great to have something like that :

->addText('start_time', [
        'required'    => true,
        'placeholder' => '00:00:00',
        'regex' => '/^(((([0-1][0-9])|(2[0-3])):?[0-5][0-9]:?[0-5][0-9]+$))/'
])

And in the back it would do something like that :

add_filter(
    'acf/validate_value/name=start_time',
    function($valid, $value, $field, $input_name) {
       if (!$valid) {
        return $valid;
    }

    $regex = '/^(((([0-1][0-9])|(2[0-3])):?[0-5][0-9]:?[0-5][0-9]+$))/';
    if (!preg_match($regex, $value)) {
        $valid = 'Please enter a string as follows: hh:mm:ss.';
    }

    return $valid;
    },
    10,
    4
);

Don't know if that would be a good idea. Tell me.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions