700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > android 号码区号判断 android 将手机号中间隐藏为星号(*)和手机号码判断

android 号码区号判断 android 将手机号中间隐藏为星号(*)和手机号码判断

时间:2020-06-16 23:21:04

相关推荐

android 号码区号判断 android 将手机号中间隐藏为星号(*)和手机号码判断

截取手机号码的方法很简单:

//截取手机号码 方法一

String phonenum = "15718807588";

if(!TextUtils.isEmpty(phonenum) && phonenum.length() > 6 ){

StringBuilder sb =new StringBuilder();

for (int i = 0; i < phonenum.length(); i++) {

char c = phonenum.charAt(i);

if (i >= 3 && i <= 6) {

sb.append('*');

} else {

sb.append(c);

}

}

ToastUtil.showImgMessage(context,sb.toString()+"1");

}

//方法二

phonenum = phonenum.substring(0, 3) + "****" + phonenum.substring(7, 11);

ToastUtil.showImgMessage(context,phonenum+"2");

//方法三:用****替换手机号码中间4位

String mobile = "15718807588";

String maskNumber = mobile.substring(0,3)+"****"+mobile.substring(7,mobile.length());

/**

* 检查是否是电话号码

*

* @return

*/

public static boolean isMobileNum(String mobiles) {

Pattern p = Pattern

.compile("^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$");

Matcher m = p.matcher(mobiles);

return m.matches();

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。