手机号加密

protected void Page_Load(object sender, EventArgs e)
{
string source = "赵娟不接,13501102353,|周先生 关机,13801305130,|,,|,";

Regex reg = new Regex("[1][3,4,5,7,8][0-9]{9}");

var matches=reg.Matches(source);

foreach (Match m in matches)
{
source = source.Replace(m.Value, code(m.Value));
}

}

private string code(string input)
{
string start = input.Substring(0, 3);
string end = input.Substring(7, 4);

return start + "****" + end;
}

posted @ 2018-08-30 16:20  ransom  阅读(353)  评论(0编辑  收藏  举报