Skip to content
Download

regex

mach::FieldValidationBuilder::regex

Adds regular expression validation.

Applies a regular expression validation rule to a string field.

FieldValidationBuilder& regex(std::string_view pattern);

A reference to the current FieldValidationBuilder instance.

Parameter Description
pattern The regular expression pattern to match.

Applying the same validation rule multiple times is allowed.

This method is not thread-safe and should only be called during validation configuration.

void validate(mach::ValidationBuilder<User>& validation) const {
validation.field(&User::username)
.regex("^[a-zA-Z0-9_]+$");
}
Name Description
email Adds email validation.
url Adds URL validation.
length Adds length validation.