xuefei
2020-12-10 eeeb7233935ea9b10e99043bdbf740ef86c9bf20
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package cn.cetc54.platform.core.common.utils;
 
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
 
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
/**
 * 用户名验证工具类
 * @author
 */
@Slf4j
public class NameUtil {
 
    public static final String regUsername = "^[a-zA-Z0-9_\\u4e00-\\u9fa5]{1,16}$";
 
    public static final String regMobile = "^[1][3,4,5,6,7,8,9][0-9]{9}$";
 
    public static final String regEmail = "^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
 
    /**
     * 由字母、数字、下划线、中文组成,不能超过16位
     */
    private static final Pattern pUsername = Pattern.compile(regUsername);
 
    /**
     * 普通用户11位手机号
     * 10、11、12开头的号码已分配给特定机构
     */
    private static final Pattern pMobile = Pattern.compile(regMobile);
 
    /**
     * 邮箱
     * http://emailregex.com/
     */
    private static final Pattern pEmail = Pattern.compile(regEmail);
 
    public static boolean username(String v){
 
        if(StrUtil.isBlank(v)){
            return false;
        }
        Matcher m = pUsername.matcher(v);
        if(m.matches()){
            return true;
        }
        return false;
    }
 
    public static boolean mobile(String v){
 
        if(StrUtil.isBlank(v)){
            return false;
        }
        Matcher m = pMobile.matcher(v);
        if(m.matches()){
            return true;
        }
        return false;
    }
 
    public static boolean email(String v){
 
        if(StrUtil.isBlank(v)){
            return false;
        }
        Matcher m = pEmail.matcher(v);
        if(m.matches()){
            return true;
        }
        return false;
    }
}