手机号和邮箱格验证工具类

public class StringTools {
/**
 * 校验是不是email
 */
	public static boolean checkIsEmail(String userId){
		if(userId == null){
			return false;
		}else{
            String format = "\\w{1,}[@][a-z0-9]{1,}[.]\\p{Lower}{1,}";
            return userId.matches(format);
		}
	}
	/**
	 * 校验是不是手机号
	 * @param userId
	 * @return
	 */
	public static boolean checkIsPhone(String userId){
		if(userId == null){
			return false;
		}else{
            String format = "[1][0-9]{10,10}";
            //1开头的11位数字
            return userId.matches(format);
		}
	}
}

  

posted @ 2022-04-15 15:22  小小菜包子  阅读(36)  评论(0)    收藏  举报