//验证联系电话
public boolean checkPhone(String phone){
if(phone.matches("\\d{4}-\\d{8}|\\d{4}-\\d{7}|\\d(3)-\\d(8)")){
return true;
}else if(phone.matches("^[1][3,5]+\\d{9}")){
return true;
}else{
return false;
}
}
//验证邮政编码
public boolean checkPost(String post){
if(post.matches("[1-9]\\d{5}(?!\\d)")){
return true;
}else{
return false;
}
}
//验证邮箱
public boolean checkEmail(String email){
if(email.matches("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*")){
return true;
}else{
return false;
}
}
Java中正则表达式验证联系电话(手机)、邮编、邮箱
最新推荐文章于 2024-08-09 03:57:57 发布