验证工具类

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;
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值