java正则表达式工具类

/**
 * 正则表达式工具类
 */
public class RegexpUtils {
    /**
     * 验证手机号
     */
    public static final String PHONE = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
    public static final String PHONE2 = "^1\\d{10}$";

    /**
     * 验证邮箱地址
     */
    public static final String EMAIL = "\\w+(\\.\\w)*@\\w+(\\.\\w{2,3}){1,3}";

    /**
     * 验证正整数
     */
    public static final String PURE_DIGITAL = "[0-9]*";

    /**
     * 验证手机号
     *
     * @param phone 手机号
     * @return 校验结果
     */
    public static boolean checkPhone(String phone) {
        return phone.matches(PHONE);
    }

    public static boolean checkPhone2(String phone) {
        return phone.matches(PHONE2);
    }

    /**
     * 验证邮箱
     *
     * @param email 邮箱
     * @return 校验结果
     */
    public static boolean checkEmail(String email) {
        return email.matches(EMAIL);
    }

    /**
     * 验证纯数字
     *
     * @param digital 数字
     * @return 校验结果
     */
    public static boolean checkPureDigital(String digital) {
        return digital.matches(PURE_DIGITAL);
    }

    /**
     * 判断字符串是否全部为中文字符组成
     *
     * @param str 检测的文字
     * @return true:为中文字符串,false:含有非中文字符
     */
    public static boolean isChineseStr(String str) {
        Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]");
        char c[] = str.toCharArray();
        for (int i = 0; i < c.length; i++) {
            Matcher matcher = pattern.matcher(String.valueOf(c[i]));
            if (!matcher.matches()) {
                return false;
            }
        }
        return true;
    }

    /**
     * 判断是否含有特殊字符
     *
     * @param str
     * @return true为包含,false为不包含
     */
    public static boolean isSpecialChar(String str) {
        String regEx = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]|\n|\r|\t";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.find();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值