SoFunction
Updated on 2025-03-11

Android uses regular expressions quickly to verify the ID number instance

During the development process, you will encounter some commonly used regular requirements.

For example, verify whether the ID number is legal. The following simple code can solve the problem instantly!

 /**
   * ID number verification
   *
   * @param idCard
   * @return
   */
 public static boolean isIdCardNum(String idCard) {
  String reg = "^\\d{15}$|^\\d{17}[0-9Xx]$";
  if (!(reg)) {
   ("Format Error!");
   return false;
  }
  return true;
 }

The above example of Android using regular expressions and verifying ID number is all the content I share with you. I hope you can give you a reference and I hope you can support me more.