程序员一代码搬运工
【Java学习心得和Java学习技术个人总结】

java模糊手机和模糊邮箱

/**
	 * 获取模糊的手机号码
	 * @param phone
	 * @return
	 */
	public static String  getPhone(String phone2){
		return   phone2.substring(0,3) + "****" + phone2.substring(7, phone2.length());
	}
	public static String  getEmail(String email){
		if(email.indexOf("@")<-1){
			return  "";
		}
		String emailname=email.substring(0, email.indexOf("@"));
		String emailAddress=email.substring(email.indexOf("@"),email.length());    //后缀名字
		if(emailname.length()>4){
			return emailname.substring(0, emailname.length()-4) +"****"+emailAddress;
		}else{
			  return  "****"+emailAddress;
		}
		
	}
	
	public static void main(String[] args) {
		String phone2 = "15988888888";
		 System.out.println(phone2);
		 String  email="hrccc@yq1012.com";
		 System.out.println(StringUtil.getEmail(email));
		 
	}

 

赞(0)
未经允许不得转载:程序员一代码搬运工 » java模糊手机和模糊邮箱
分享到: 更多 (0)