Derive Macro webforms::validate::ValidateForm
source · #[derive(ValidateForm)]
{
// Attributes available to this derive:
#[validate]
#[validate_regex]
#[validate_match]
}
Expand description
Import and re-export the macro Derives the ValidateForm trait from for a given struct
Different types have different available validate tags. Using an invalid attribute tag on an type (e.g., max_length on an int type) will cause the compiler to panic.
Type: String
min_length
- Minimum length of the stringmax_length
- Maximum length of the stringregex
- Input must match the supplied regular expressionemail
- Special regex to validate an email address
Using either the regex
or email
attributes requires your crate
to depend on both the regex and lazy_static crates. lazy_static is
required to minimize the number of times a given regex is compiled
Type: Integer
min_value
- Minimum value of this intmax_value
- Maxium value of this int
Example
ⓘ
#[derive(ValidateForm)]
struct LoginForm {
/// Username must between 4 and 16 characters
#[validate(min_length = 4)]
#[validate(max_length = 16)]
pub username: String,
///Email must conform to the email regex provided
#[validate(email)]
pub email: String,
}