常用手机号,邮箱,用户名 ,昵称校验工具类

本文介绍了一个实用的参数校验工具类,包括手机号、密码、昵称、邮箱及社交媒体账号的合法性验证方法。通过正则表达式进行精确匹配,确保输入数据的有效性和安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


import java.util.regex.Matcher;
import java.util.regex.Pattern;

/** 
* @ClassName: VerifyUtil 
* @Description:参数校验工具类
* @author John Hawkings
* @date 2016年12月9日 下午3:45:50  
*/
public class VerifyUtil {
    /**
     * 检查手机号是否合法
     * 
     * @param phone
     * @return
     */
    public static boolean verifyPhone(String phone) {
    String regExp =  "^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$";
    Pattern p = Pattern.compile(regExp);
    Matcher m = p.matcher(phone);
    return m.matches();
    }

    /**
     * 检查密码是否合法
     * 
     * @param phone
     * @return
     */
    public static boolean verifyPwd(String password){
        String regExp =  "^[a-zA-Z0-9]{6,22}$";
        Pattern p = Pattern.compile(regExp);
        Matcher m = p.matcher(password);
        return m.matches();
    }

    /**
     * 检查昵称是否合法
     * 
     * @param phone
     * @return
     */
    public static boolean verifyNickName(String nick){
        if(nick.length()>0&&nick.length()<=12){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 检查邮箱是否合法
     * 
     * @param phone
     * @return
     */
    public static boolean verifyEmail(String email){
        String regExp =  "^(www\\.)?\\w+@\\w+(\\.\\w+)+$";
        Pattern p = Pattern.compile(regExp);
        Matcher m = p.matcher(email);
        return m.matches();
    }

    /**
     * 检验微信是否合法
     * @param weixin
     * @return
     */
    public static boolean verifyWeixin(String weixin){
        String regExp =  "^[a-zA-Z]{1}[-_a-zA-Z0-9]{5,19}+$";
        Pattern p = Pattern.compile(regExp);
        Matcher m = p.matcher(weixin);
        return m.matches();
    }

    /**
     * 检验qq是否合法
     * @param qq
     * @return
     */
    public static boolean verifyQq(String qq){
        String regExp =  "[1-9][0-9]{4,12}";
        Pattern p = Pattern.compile(regExp);
        Matcher m = p.matcher(qq);
        return m.matches();
    }


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值