1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use lazy_static::lazy_static;
use regex::Regex;
use time::Date;

pub fn email(email: &str) -> bool {
    if email.len() > 64 {
        return false;
    }

    lazy_static! {
        static ref RE: Regex =
            Regex::new(r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$").unwrap();
    }
    RE.is_match(email)
}

pub fn password(password: &str) -> bool {
    if password.len() < 8 || password.len() > 64 {
        return false;
    }

    true
}

pub fn first_name(first_name: &str) -> bool {
    name(first_name)
}

pub fn last_name(last_name: &str) -> bool {
    name(last_name)
}

fn name(name: &str) -> bool {
    lazy_static! {
        static ref RE: Regex = Regex::new(r"^[a-zA-Z]{2,32}$").unwrap();
    }
    RE.is_match(name)
}

pub fn birthday(birthday: &Date) -> bool {
    birthday >= &Date::from_ordinal_date(1900, 1).unwrap()
}

pub fn token_name(token_name: &str) -> bool {
    lazy_static! {
        static ref RE: Regex = Regex::new(r"^[a-zA-Z0-9 ]{1,64}$").unwrap();
    }
    RE.is_match(token_name)
}