PHP
$num = "13966778888"
$str = substr_replace($num,'****',3,4);
IOS
NSString *originTel = @"13722223333";
NSString *tel = [originTel stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
NSLog(@"tel:%@",tel);
//输出
tel:137****3333
可以调整range,隐藏不同的位置
java
[摘要:phone.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2"); 152****4799 idCard.replaceAll("(\\d{4})\\d{10}(\\w{4})","$1*****$2"); 4304*****7733 $1、$2、……透露表现正则表达]
phone.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
152****4799
idCard.replaceAll("(\\d{4})\\d{10}(\\w{4})","$1*****$2");
4304*****7733
$1、$2、……表示正则表达式里面第一个、第二个、……括号里面的匹配内容
android
String mobile = "12345671234";
String maskNumber = mobile.substring(0,3)+"****"+mobile.substring(7,mobile.length());
js
<input type="text" value="请输入手机号码" maxlength="11" onkeyup="if(value.length>3&&value.length<8){value=value.substring(0,value.length-1)+'*'}" onfocus="value=''" onblur="if(value==''){value='请输入手机号码'}"/>