zoukankan      html  css  js  c++  java
  • 手机号/身份证加星处理

    java

    public class Test {  
        public static void main(String[] args) {  
            String phone = "18771638976";  
            System.out.println(phone.replaceAll("(\d{3})\d{4}(\d{4})","$1****$2"));  //11位 187****8976
    
            String idCard = "410721992081659807";  
            System.out.println(idCard.replaceAll("(\d{4})\d{10}(\d{4})","$1****$2")); //18位 4107**********9807  只适用于纯数字不带字母
        }  
    }  
    

    javaScript

    phone.substr(0, 3) + '****' + phone.substr(7);
    phone=phone.replace(/(w{3})w*(w{4})/, '$1****$2');
    
    cardNo = cardNo.substring(0, 6) + "********" + cardNo.substring(14, 18);
    cardNo=cardNo.replace(/(w{6})w*(w{4})/, '$1******$2'); 适用于纯数字,适用于数字+字母
    
  • 相关阅读:
    FastAPI(5)- 查询参数 Query Parameters
    FastAPI(4)- 路径参数 Path Parameters
    FastAPI(3)- uvicorn.run()
    Python
    Python
    Python
    Python
    Python
    Python
    Python
  • 原文地址:https://www.cnblogs.com/xiaoyinger/p/12159630.html
Copyright © 2011-2022 走看看