valico/json_dsl/validators/
regex.rs
1use serde_json::{Value};
2use regex;
3
4use super::super::errors;
5
6impl super::Validator for regex::Regex {
7 fn validate(&self, val: &Value, path: &str) -> super::ValidatorResult {
8
9 let string = strict_process!(val.as_str(), path, "The value must be a string");
10
11 if self.is_match(string) {
12 Ok(())
13 } else {
14 Err(vec![
15 Box::new(errors::WrongValue {
16 path: path.to_string(),
17 detail: Some("Value is not matched by required pattern".to_string())
18 })
19 ])
20 }
21 }
22}