对电话号码进行格式校验、脱密、加密、解密、掩码等的操作介绍
随着人们对个人信息保护意识的增强,各大互联网公司对用户个人私密信息的保护日益受到重视。结合我们的实际业务场景,就需要经常使用到对手机号码、座机号码、分机号码进行正确性校验以及对电话号码进行掩码等的操作,本篇文章介绍如何对电话号码进行“格式校验、脱密、加密、解密、掩码”等的操作的一系列操作。
一 、源码:
- 工具内容
/**
* 电话号码处理工具
*
* @author Ligang.Wang[wlgchun@163.com]
* @date 2017年8月22日 下午3:10:50
*/
package com.wlgdo.avatar.common.utils;
public class TelephoneUtil {
public static boolean FormatTransfer = true;// 是否将电话号码统一格式化为xxx-xxxx-xxx
public static boolean MosaicSwtich = true;// 是否将电话号码统一格式化为xxx-xxxx-xxx
public static final String MosaicMask = "*****************";// 声明常量掩码,最大支持18位
public static final String[] TelephoneSeparator = new String[]{"-", "\\(", "\\)", "(", ")", "转", "·"};// 几个常见的座机号码常见分隔符
/**
* 添加掩码
*
* @param telePhoneNum
* @return String
* @author Ligang.Wang[wlgchun@163.com]
* @date 2017年8月22日下午6:39:03
*/
public static String mosaic(String telePhoneNum) {
return isAlpha(telePhoneNum, TelephoneType.Mobile) ? mosaic(telePhoneNum, TelephoneType.Mobile) :
mosaic(telePhoneNum, TelephoneType.Telephone);
}
public static String mosaic(String telePhoneNum, TelephoneType telephoneType) {
return telephoneType.mosaic(telePhoneNum);
}
/**
* 格式化电话号码
*
* @param telePhoneNum
* @return String
* @author Ligang.Wang[wlgchun@163.com]
* @date 2017年8月22日下午6:39:14
*/
public static String format(String telePhoneNum) {
return isAlpha(telePhoneNum, TelephoneType.Mobile) ? Tel