Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use java regular expression to detect the legitimacy of phone number and identity number

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use java regular expression to detect the legitimacy of phone number and identity number". In daily operation, it is believed that many people have doubts about how to use java regular expression to detect the legitimacy of phone number and identity number. The editor consulted all kinds of materials and sorted out a simple and useful method of operation. I hope it will be helpful to answer the question of "how to use java regular expressions to detect the legitimacy of phone numbers and identity numbers"! Next, please follow the editor to study!

In web development, we often use to verify the phone number and ID card format, which is integrated into a tool class here.

Package com.zzb.business.customerInfo.utils;import java.util.regex.Matcher;import java.util.regex.Pattern Public class FormUtils {private static String regularExpression = "(^ [1-9]\\ d {5} (18 | 19 | 20)\\ d {2} ((0 [1-9])) | (10 | 11 | 12)) ([0-2] [1-9]) | 10 | 20 | 30 | 31)\ d {3} [0-9Xx] $) |" + "(^ [1-9]\ d {5}\ d {2} (0 [1-9])) | (10 | 11 | 12) () ([0-2] [1-9]) | 10 | 20 | 30 | 31)\\ d {3} $) " Private static String telephoneExpression = "^ [1] [3 public static Boolean checkTelephone 4, 5 5, 7, 8] [0-9] {9} $"; public static Boolean checkIdCard (String idCard) {Pattern pa = Pattern.compile (regularExpression); Matcher m = pa.matcher (idCard); return m.matches ();} public static Boolean checkTelephone (String telephone) {Pattern pa = Pattern.compile (telephoneExpression); Matcher m = pa.matcher (telephone) Return m.matches ();}} at this point, the study on "how to use java regular expressions to detect the legitimacy of phone numbers and identity numbers" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report