替换手机和身份证C#

 

[HttpPost]
        public JsonResult DocumentList(DocumentQueryRequest request)
        {
            var result = PayProvider.DocumentService.DocumentList(request);
            Regex regexCard = new Regex(@"\d{15,25}");
            Regex regexMobile = new Regex(@"[1][3-8]\d{9}");
            foreach (var r in result.DataList)
            {
                r.DocumentIdStr = r.DocumentId.ToString();
                foreach (var d in r.Entries)
                {
                    d.AccountDocumentEntryIdStr = d.AccountDocumentEntryId.ToString();
                    string EntryRemark = d.EntryRemark;
                    if (!string.IsNullOrWhiteSpace(EntryRemark))
                    {
                        if (regexMobile.IsMatch(EntryRemark))
                        {
                            MatchCollection matchMobile = regexMobile.Matches(EntryRemark);
                            foreach (Match m in matchMobile)
                            {
                                string _mobile = m.Groups[0].Value;
                                _mobile = _mobile.Substring(0, 3) + "****" + _mobile.Substring(7, 4);
                                EntryRemark = regexMobile.Replace(EntryRemark, _mobile);
                            }
                        }
                        if (regexCard.IsMatch(EntryRemark))
                        {
                            MatchCollection matchCard = regexCard.Matches(EntryRemark);
                            foreach (Match m in matchCard)
                            {
                                string _card = m.Groups[0].Value;
                                _card = _card.Substring(0, 5) + "****" + _card.Substring(_card.Length - 5, 5);
                                EntryRemark = regexCard.Replace(EntryRemark, _card);
                            }
                        }  
                        d.EntryRemark = EntryRemark;
                    }
                }
            }
            return Json(result);
        }

 

posted @ 2017-04-10 10:43  wjl910  阅读(205)  评论(0)    收藏  举报