1use lazy_static::lazy_static;
2use regex::Regex;
3use time::Date;
4
5pub fn email(email: &str) -> bool {
6 if email.len() > 64 {
7 return false;
8 }
9
10 lazy_static! {
11 static ref RE: Regex =
12 Regex::new(r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$").unwrap();
13 }
14 RE.is_match(email)
15}
16
17pub fn password(password: &str) -> bool {
18 if password.len() < 8 || password.len() > 64 {
19 return false;
20 }
21
22 true
23}
24
25pub fn first_name(first_name: &str) -> bool {
26 name(first_name)
27}
28
29pub fn last_name(last_name: &str) -> bool {
30 name(last_name)
31}
32
33fn name(name: &str) -> bool {
34 lazy_static! {
35 static ref RE: Regex = Regex::new(r"^[a-zA-Z]{2,32}$").unwrap();
36 }
37 RE.is_match(name)
38}
39
40pub fn birthday(birthday: &Date) -> bool {
41 birthday >= &Date::from_ordinal_date(1900, 1).unwrap()
42}
43
44pub fn token_name(token_name: &str) -> bool {
45 lazy_static! {
46 static ref RE: Regex = Regex::new(r"^[a-zA-Z0-9 ]{1,64}$").unwrap();
47 }
48 RE.is_match(token_name)
49}