Skip to main content

teaql_tool_std/
validate.rs

1use email_address::EmailAddress;
2use url::Url;
3use std::str::FromStr;
4
5pub struct ValidateTool;
6
7impl ValidateTool {
8    pub fn new() -> Self {
9        Self
10    }
11
12    pub fn email(&self, val: &str) -> bool {
13        EmailAddress::is_valid(val)
14    }
15
16    pub fn url(&self, val: &str) -> bool {
17        Url::from_str(val).is_ok()
18    }
19
20    pub fn min_length(&self, val: &str, min: usize) -> bool {
21        val.chars().count() >= min
22    }
23
24    pub fn max_length(&self, val: &str, max: usize) -> bool {
25        val.chars().count() <= max
26    }
27}
28
29impl Default for ValidateTool {
30    fn default() -> Self {
31        Self::new()
32    }
33}