Skip to content
Download

field

mach::validation::ValidationBuilder<T>::field

Configures validation for a field.

Creates a validation builder for the specified field of T.

The returned builder may be used to add validation rules that apply to that field.

template <typename Field>
[[nodiscard]] validation::FieldValidationBuilder<T, Field> field(Field T::* field);

A FieldValidationBuilder for configuring validation rules for the specified field.

Parameter Description
Field The type of the selected field.
Parameter Description
field A pointer to the member field to configure.

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

struct RegisterRequest {
std::string username;
std::string email;
int age;
void validate(mach::ValidationBuilder<RegisterRequest>& validation) const {
validation.field(&RegisterRequest::username)
.length(3, 20)
.regex(R"(^[A-Za-z0-9_]+$)");
validation.field(&RegisterRequest::email)
.email();
validation.field(&RegisterRequest::age)
.range(18, 120);
}
};
MACH_DEFINE_JSON(RegisterRequest, username, email, age)
Name Description
FieldValidationBuilder Configures validation rules for a field.