Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

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

Shulou Source: shulou.com Published: 2022-06-01 23:15:29 10月03日 Update

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!

Tags: Number phone number identity legality legality regularity expression Detection Learning more help practical next tools articles methods formats Theory knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei Apple Redmi Linux