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

Add format checkers to an existing validator. #329

Open
zaun opened this issue Sep 18, 2024 · 2 comments
Open

Add format checkers to an existing validator. #329

zaun opened this issue Sep 18, 2024 · 2 comments

Comments

@zaun
Copy link

zaun commented Sep 18, 2024

Something like:

validator.set_format_check("url", [](const std::string &value) {
    const std::regex uri_regex(R"(^https?:\/\/[^\s]+$)");
    if (!std::regex_match(value, uri_regex)) {
        throw std::invalid_argument("Invalid URI format: " + value);
    }
});

Would allow easy adding of format checkers to an existing validator. It also, at least in my opinion, is easier to read than a monolithic format checker. A setup like this would allow the default checkers to be added automatically, but still let the user overwrite them with their own if they want.

@pboettch
Copy link
Owner

Nice idea. Are you able to develop this feature?

@zaun
Copy link
Author

zaun commented Sep 19, 2024

I can look into it.

Would you still want the ability to have the monolithic format checker? I would recommend removing it for simplicity, but that would be a breaking change to the API.

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

2 participants