aboutsummaryrefslogtreecommitdiffstats
path: root/validator_derive/src
diff options
context:
space:
mode:
Diffstat (limited to 'validator_derive/src')
-rw-r--r--validator_derive/src/lib.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/validator_derive/src/lib.rs b/validator_derive/src/lib.rs
index 7a21ac8..68a4b2e 100644
--- a/validator_derive/src/lib.rs
+++ b/validator_derive/src/lib.rs
@@ -129,6 +129,14 @@ fn expand_validation(ast: &syn::MacroInput) -> quote::Tokens {
}
)
},
+ &Validator::Regex(ref re) => {
+ let re_ident = syn::Ident::new(re.clone());
+ quote!(
+ if !#re_ident.is_match(&self.#field_ident) {
+ errors.add(#name, "regex");
+ }
+ )
+ },
});
}
}
@@ -437,6 +445,12 @@ fn find_validators_for_field(field: &syn::Field, field_types: &HashMap<String, S
None => error("invalid argument for `contains` validator: only strings are allowed"),
};
},
+ "regex" => {
+ match lit_to_string(val) {
+ Some(s) => validators.push(Validator::Regex(s)),
+ None => error("invalid argument for `regex` validator: only strings are allowed"),
+ };
+ }
"must_match" => {
match lit_to_string(val) {
Some(s) => {