对电话号码验证、掩码、加密适用匿名类处理

如何对电话号码进行有效判断,并对其添加掩码,加密等相关措施,本实例是我们在实际工作中遇到的情况进行了归类总结,具有很强的适用性,分享出来给大家!!

 

 

package main;

/**
 * 电话号码处理工具
 * 
 * @author Ligang.Wang[wlgchun@163.com]
 * @date 2017年8月22日 下午3:10:50
 */
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[] { "-", "\\(", "\\)", "(", ")", "转", "·" };// 几个常见的座机号码常见分隔符


/**
* 添加掩码
* 
* @author Ligang.Wang[wlgchun@163.com]
* @date 2017年8月22日下午6:39:03
* @param telePhoneNum
* @return String
*/
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);
}


/**
* 格式化电话号码
* 
* @author Ligang.Wang[wlgchun@163.com]
* @date 2017年8月22日下午6:39:14
* @param telePhoneNum
* @return String
*/
public static String format(String telePhoneNum) {
return isAlpha(telePhoneNum, TelephoneType.Mobile) ? TelephoneType.Mobile.format(telePhoneNum) : TelephoneType.Telephone.format(telePhoneNum);
}


public static String format(String telePhoneNum, TelephoneType telephoneType) {
return telephoneType.format(telePhoneNum);
}


/**
* 判断是否电话号码
* 
* @author Ligang.Wang[wlgchun@163.com]
* @date 2017年8月22日下午6:39:32
* @param telePhoneNum
* @return boolean
*/
public static boolean isAlpha(String telePhoneNum) {
return !isAlpha(telePhoneNum, TelephoneType.Mobile) && !isAlpha(telePhoneNum, TelephoneType.Telephone);
}


public static boolean isAlpha(String telePhoneNum, TelephoneType telephoneType) {
return null != telephoneType.format(telePhoneNum);
}


/**
* 加密手机号码
* 
* @author Ligang.Wang[wlgchun@163.com]
* @date 2017年8月22日下午6:39:49
* @param telphoneNum
* @return String
*/
public static String encrypt(String telphoneNum) {
if (!isAlpha(telphoneNum)) {
System.out.println("不是通常的电话号码");
return null;
}
String resource = Thread.currentThread().getStackTrace()[2].getClassName() + "." + Thread.currentThread().getStackTrace()[2].getMethodName();
System.out.println("调用加密得资源是:" + resource);
return "自定义加密算法";
}


/**
* 解密手机号码
* 
* @author Ligang.Wang[wlgchun@163.com]
* @date 2017年8月22日下午6:39:58
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值