JAVA验证字段正则表达式相关

JAVA验证字段正则表达式相关

/**
 *邮箱格式验证 
 */
public static boolean checkEmail(String email){
    boolean flag = false;
    try{
            String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
            Pattern regex = Pattern.compile(check);
            Matcher matcher = regex.matcher(email);
            flag = matcher.matches();
        }catch(Exception e){
            flag = false;
        }
    return flag;
}
/**
 * 手机号码格式验证
 */
public static boolean checkMobile(String mobile){
    boolean flag = false;
    try{
            Pattern regex = Pattern.compile("^1[3|4|5|7|8][0-9]\\d{4,8}$");
            Matcher matcher = regex.matcher(mobile);
            flag = matcher.matches();
        }catch(Exception e){
            flag = false;
        }
    return flag;
}
/**
 * 姓名格式验证
 * @param mobile
 * @return
 */
public static boolean checkName(String name){
    boolean flag = false;
    try{
            Pattern regex = Pattern.compile("^(([\u4e00-\u9fa5]{2,8})||([a-zA-Z]{2,16}))$");
            Matcher matcher = regex.matcher(name);
            flag = matcher.matches();
        }catch(Exception e){
            flag = false;
        }
    return flag;
}
/**
 * 地址格式验证
 * @param mobile
 * @return
 */
public static boolean checkAdress(String name){
    boolean flag = false;
    try{
            Pattern regex = Pattern.compile("^([\u4e00-\u9fa50-9]{2,30})$");
            Matcher matcher = regex.matcher(name);
            flag = matcher.matches();
        }catch(Exception e){
            flag = false;
        }
    return flag;
}
/**
 * 电话号码格式验证
 * @param mobile
 * @return
 */
public static boolean checkPhone(String phone){
    boolean flag = false;
    try{
            Pattern regex = Pattern.compile("^(\\(?\\d{3,4}[-\\)]?\\d{7,8})$");
            Matcher matcher = regex.matcher(phone);
            flag = matcher.matches();
        }catch(Exception e){
            flag = false;
        }
    return flag;
}
/**
 * 可输字符,字母,数字格式验证
 * @param mobile
 * @return
 */
public static boolean checkAll(String name){
    boolean flag = false;
    try{
            Pattern regex = Pattern.compile("^([\u4e00-\u9fa50-9a-zA-Z]{2,30})$");
            Matcher matcher = regex.matcher(name);
            flag = matcher.matches();
        }catch(Exception e){
            flag = false;
        }
    return flag;
}
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值