1. 程式人生 > >輔助函式

輔助函式

java後臺驗證手機號,郵箱格式正則匹配:

private Integer getType(String account) {
    String mobile = "^((1[3,5,8][0-9])|(14[5,7])|(17[0,1,6,7,8]))\\d{8}$";
    String email = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
    if (!StringUtil.isBlank(account)) {
        boolean flag = Pattern.matches(email, account);
        if (flag) {
            return 0;
        } else {
            boolean flag2 = Pattern.matches(mobile, account);
            if (flag2) {
                return 1;
            }
        }
    }
    return 2;
}