Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: Add regex parameter #145

Open
Androlax2 opened this issue Oct 12, 2021 · 0 comments
Open

enhancement: Add regex parameter #145

Androlax2 opened this issue Oct 12, 2021 · 0 comments

Comments

@Androlax2
Copy link
Contributor

Androlax2 commented Oct 12, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant