package com.common.web.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
public class Tools {
public static String getEmailSite(String email){
String httpAdress = null;
String emailStr = StringUtils.substringAfterLast(email, "@");
if("qq.com".equals(emailStr)){
httpAdress = "http://mail.qq.com";
}else if("gmail.com".equals(emailStr)){
httpAdress = "http://mail.google.com";
}else if("sina.com".equals(emailStr)){
httpAdress = "http://mail.sina.com.cn";
}else if("163.com".equals(emailStr)){
httpAdress = "http://mail.163.com";
}else if("126.com".equals(emailStr)){
httpAdress = "http://mail.126.com";
}else if("yeah.net".equals(emailStr)){
httpAdress = "http://www.yeah.net/";
}else if("sohu.com".equals(emailStr)){
httpAdress = "http://mail.sohu.com/";
}else if("tom.com".equals(emailStr)){
httpAdress = "http://mail.tom.com/";
}else if("139.com".equals(emailStr)){
httpAdress = "http://mail.10086.cn/";
}else if("sogou.com".equals(emailStr)){
httpAdress = "http://mail.sogou.com/";
}else if("hotmail.com".equals(emailStr)){
httpAdress = "http://www.hotmail.com";
}else if("189.com".equals(emailStr)){
httpAdress = "http://webmail16.189.cn/webmail/";
}else if("yahoo.com.cn".equals(emailStr)){
httpAdress = "http://mail.cn.yahoo.com/";
}else if("yahoo.cn".equals(emailStr)){
httpAdress = "http://mail.cn.yahoo.com/";
}else if("foxmail.coom".equals(emailStr)){
httpAdress = "http://www.foxmail.com";
}else if("eyou.com".equals(emailStr)){
httpAdress = "http://www.eyou.com/";
}else if("21cn.com".equals(emailStr)){
httpAdress = "http://mail.21cn.com/";
}else if("188.com".equals(emailStr)){
httpAdress = "http://www.188.com/";
}else if("live.com".equals(emailStr)){
httpAdress = "http://login.live.com/";
}else if("live.cn".equals(emailStr)){
httpAdress = "http://login.live.cn/";
}else if("live.com.cn".equals(emailStr)){
httpAdress = "http://login.live.com.cn";
}
return httpAdress;
}
/**
* 验证邮箱
*
* @param email
* @return
*/
public static boolean checkEmail(String email) {
boolean flag = false;
try {
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);
flag = matcher.matches();
} catch (Exception e) {
flag = false;
}
return flag;
}
/**
* 验证手机号码
*
* @param mobiles
* @return
*/
public static boolean checkMobileNumber(String mobileNumber) {
boolean flag = false;
try {
Pattern regex = Pattern.compile("^(((13[0-9])|(15([0-3]|[5-9]))|(18[0-9])|(17[0-9])|(14[0-9]))\\d{8})|(0\\d{2}-\\d{8})|(0\\d{3}-\\d{7})$");
Matcher matcher = regex.matcher(mobileNumber);
flag = matcher.matches();
} catch (Exception e) {
flag = false;
}
//110开头是马甲
if(mobileNumber.startsWith("110")){
flag=true;
}
return flag;
}
/**
* 验证登录密码
*
* @param loginPWD
* @return
*/
public static boolean checkPasswrod(String password) {
boolean flag = false;
try {
Pattern regex = Pattern
.compile("^[a-zA-Z0-9`~!@#$%^&*()-_=+,.?/|{}]{6,20}$");
Matcher matcher = regex.matcher(password);
flag = matcher.matches();
} catch (Exception e) {
flag = false;
}
return flag;
}
/**
* 验证汉字
*
* @param realName
* @return
*/
public static boolean checkRealName(String realName) {
boolean flag = false;
try {
Pattern regex = Pattern.compile("^[\u4e00-\u9fa5]{2,10}");
Matcher matcher = regex.matcher(realName);
flag = matcher.matches();
} catch (Exception e) {
flag = false;
}
return flag;
}
/**
* 验证身份证
*
* @param identityNo
* @return
*/
public static boolean checkIdentityNo(String identityNo) {
boolean flag = false;
try {
Pattern regex = Pattern
.compile("(^\\d{17}([0-9]|X|x)$)|(^\\d{15}$)");
Matcher matcher = regex.matcher(identityNo);
flag = matcher.matches();
} catch (Exception e) {
flag = false;
}
return flag;
}
/**
* @Desc: 隐藏手机号码
*
*/
public static String HiddenMobile(String mobile) {
if (StringUtils.isBlank(mobile) || mobile.length() < 11) {
return mobile;
}
mobile = StringUtils.left(mobile, 3) + "****" + StringUtils.right(mobile, 4);
return mobile;
}
}
验证工具类
最新推荐文章于 2019-04-15 11:37:53 发布