idfy_common/utils/
validation.rs

1pub fn check_email(email: &str) -> bool {
2    email.contains('@') && email.split('@').all(|part| !part.is_empty())
3    // email.contains(r"^([a-z0-9_+]([a-z0-9_+.]*[a-z0-9_+])?)@([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6})")
4}
5
6pub fn check_pin(number: &str) -> bool {
7    let number = number.trim();
8    let length = number.len();
9
10    // Check if the number starts with a "+" and has at least 5 digits
11    if length <= 6 && length >= 4 && number[0..].chars().all(|c| c.is_digit(10)) {
12        true
13    } else {
14        false
15    }
16}
17
18pub fn check_phone(number: &str) -> bool {
19    let number = number.trim();
20    let length = number.len();
21
22    // Check if the number starts with a "+" and has at least 5 digits
23    if length == 7 && number[0..].chars().all(|c| c.is_digit(10)) {
24        true
25    } else {
26        false
27    }
28}
29
30pub fn check_password(password: &str) -> bool {
31    // (bool, bool, bool, bool, bool, bool)
32    let mut no_whitespace = vec![];
33    let mut has_upper = vec![];
34    let mut has_lower = vec![];
35    let mut has_digit = vec![];
36    let mut has_symbol = vec![];
37    let check_symbols_vec = vec![
38        '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '|', '-', '=', '\\', '<', ',',
39        '>', '.', '?', '/', '{', '[', '}', ']', ':', ';', '"', '\'',
40    ];
41
42    for c in password.chars() {
43        no_whitespace.push(c.is_whitespace());
44        has_lower.push(c.is_lowercase());
45        has_upper.push(c.is_uppercase());
46        has_symbol.push(check_symbols_vec.contains(&c));
47        has_digit.push(c.is_digit(10));
48    }
49
50    // (
51    //     !no_whitespace.contains(&true),
52    //     has_upper.contains(&true),
53    //     has_lower.contains(&true),
54    //     has_digit.contains(&true),
55    //     has_symbol.contains(&true),
56    //     password.len() >= 8,
57    // )
58
59    !no_whitespace.contains(&true)
60        && true
61        && has_lower.contains(&true)
62        && has_digit.contains(&true)
63        && true
64        && password.len() >= 8
65}