每天一篇之记录一波正则表达式验证
判断手机是否正确
public static boolean isMobile(String mobile){
if(mobile==null||mobile.isEmpty())
{
return false;
}
String check = "^(((13[0-9])|(14[579])|(15([0-3]|[5-9]))|(16[6])|(17[0135678])|(18[0-9])|(19[89]))\\d{8})$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(mobile);
return matcher.matches();
}
判断邮箱是否正确
public static boolean isEmail(String email){
if(email==null||email.isEmpty())
{
return false;
}
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);
return matcher.matches();
}
QQ号验证
public static boolean isQQ(String qq){
if(qq==null||qq.isEmpty())
{
return false;
}
String check = "^[1-9][0-9]{4,12}$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(qq);
return matcher.matches();
}
固定电话验证
public static boolean isTelphone(String str){
if(str==null||str.isEmpty())
{
return false;
}
String check = "^[0][1-9]{2,3}-[0-9]{5,10}$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(str);
return matcher.matches();
}
字符串是否符合 格式为2017-12-25 的日期
public static boolean isTrueDay(String str){
if(str==null||str.isEmpty())
{
return false;
}
String check = "\\d{4}\\-(0?[1-9]|[1][012])\\-(0?[1-9]|[12][0-9]|3[01])";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(str);
return matcher.matches();
}
是否正确ip
public static boolean isIP(String ip)
{
if(ip==null||ip.isEmpty())
{
return false;
}
String check = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])(\\.(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)){3}$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(ip);
return matcher.matches();
}
获取日期格式为 yyyy-MM-dd 的昨天
public static String getYesterday()
{
Date date=new Date();
//Calendar calendar =new GregorianCalendar();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(calendar.DATE, -1);
date = calendar.getTime();
SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd");
String dateString = format.format(date);
return dateString;
}
就暂时记录这么多,,,欢迎大家找茬