chinese-validator-core 0.1.0

Core validation logic for Chinese data (address,id_card, license_plate,name, phone, postal_code,qq,username,etc.)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//! 用户名验证

/// 验证用户名
pub fn validate_username(username: &str, strict: bool) -> bool {
    if username.is_empty() {
        return false;
    }

    if strict {
        username.len() >= 4 && username.len() <= 20
    } else {
        username.len() >= 2 && username.len() <= 30
    }
}