import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author
* @date 2019/9/7 7:57
*/
public class FormatUtil {
//判断是否为邮箱
public static boolean isMailFormat(String mail){
String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
Pattern mailRegex = Pattern.compile(check);
Matcher matcher = mailRegex.matcher(mail);
return matcher.matches();
}
public static boolean isPhoneFormat(String phone){
//判断是否为座机
boolean flag2 = false;
Matcher m1;
Pattern p1 = Pattern.compile("^[0][1-9]{2,3}-[0-9]{5,10}$"); // 验证带区号的
Pattern p2 = Pattern.compile("^[1-9]{1}[0-9]{5,8}$"); // 验证没有区号的
if (phone.length() > 9) {
m1 = p1.matcher(phone);
flag2 = m1.matches();
} else {
m1= p2.matcher(phone);
flag2 = m1.matches();
}
//判断是否为手机
Pattern phoneRegex = Pattern.compile("^((13[0-9])|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[3,5,6,7,8])" +
"|(18[0-9])|(19[8,9]))\\d{8}$"); // 验证手机号
Matcher m = phoneRegex.matcher(phone);
return m.matches()||flag2;
}
}
java判断是否是邮箱,座机,手机的封装函数
最新推荐文章于 2024-07-01 03:18:12 发布