Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to hide 4 digits in the middle of mobile phone number by using regular expression

Shulou Source: shulou.com Published: 2022-06-02 11:15:54 10月03日 Update

This article shows you how to use regular expressions to hide 4 digits in the middle of your mobile phone number. the content is concise and easy to understand, which can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. Hide the middle four digits of the mobile phone number and become 186 million digits and 9877 digits.

/ * * Hidden some mobile phone numbers * @ param phone * @ return * / public static String hidePhoneNum (String phone) {String result = "; if (phone! = null & &!" .equals (phone)) {if (isMobileNum (phone)) {result = phone.substring (0,3) + "*" + phone.substring (7);}} return result;}

two。 Determine whether it is a mobile phone number.

/ * check whether it is a phone number * * @ return * / public static boolean isMobileNum (String mobiles) {Pattern p = Pattern. Compile ("^ ((13 [0-9]) | (14 [0-9]) | (15 [^ 4,\\ D]) | (18 [0-9])\\ d {8} $"); Matcher m = p.matcher (mobiles); return m.matches () } the above content is how to use regular expressions to hide the four digits in the middle of the mobile phone number. have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Mobile phone number number digit number regular expression content skill knowledge conciseness brevity namely article more phone number article industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Microsoft Linux Huawei MySQL