field
mach::validation::ValidationBuilder<T>::field
Configures validation for a field.
Description
Section titled “Description”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.
Syntax
Section titled “Syntax”template <typename Field>[[nodiscard]] validation::FieldValidationBuilder<T, Field> field(Field T::* field);Return Value
Section titled “Return Value”A FieldValidationBuilder for configuring validation rules for the specified field.
Template Parameters
Section titled “Template Parameters”| Parameter | Description |
|---|---|
Field |
The type of the selected field. |
Parameters
Section titled “Parameters”| Parameter | Description |
|---|---|
field |
A pointer to the member field to configure. |
Thread Safety
Section titled “Thread Safety”This function is not thread-safe and should only be called during validation configuration.
Example
Section titled “Example”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)See Also
Section titled “See Also”| Name | Description |
|---|---|
FieldValidationBuilder |
Configures validation rules for a field. |