SoFunction
Updated on 2025-04-07

A complete example of RegexUtil, a very useful regular expression tool class in Android development

This article describes the very useful regular expression tool class RegexUtil in Android development. Share it for your reference, as follows:

/*********************************************************************
  * Regular Expression Tool
  *
  * @author
  * @version 1.0
  *********************************************************/
public class RegexUtil {
  /**
    * License plate number Pattern
    */
  public static final Pattern PLATE_NUMBER_PATTERN = Pattern
      .compile("^[\u0391-\uFFE5]{1}[a-zA-Z0-9]{6}$");
  /**
    * ID number Pattern
    */
  public static final Pattern ID_CODE_PATTERN = Pattern
      .compile("^[a-zA-Z0-9]+$");
  /**
    * Encoding Pattern
    */
  public static final Pattern CODE_PATTERN = Pattern
      .compile("^[a-zA-Z0-9]+$");
  /**
    * Landline phone code Pattern
    */
  public static final Pattern PHONE_NUMBER_PATTERN = Pattern
      .compile("0\\d{2,3}-[0-9]+");
  /**
    * Postal Code Pattern
    */
  public static final Pattern POST_CODE_PATTERN = ("\\d{6}");
  /**
    * Area Pattern
    */
  public static final Pattern AREA_PATTERN = ("\\d*.?\\d*");
  /**
    * Mobile phone number Pattern
    */
  public static final Pattern MOBILE_NUMBER_PATTERN = Pattern
      .compile("\\d{11}");
  /**
    * Bank account Pattern
    */
  public static final Pattern ACCOUNT_NUMBER_PATTERN = Pattern
      .compile("\\d{16,21}");
  /**
    * Is the license plate number correct?
    *
    * @param s
    * @return
    */
  public static boolean isPlateNumber(String s) {
    Matcher m = PLATE_NUMBER_PATTERN.matcher(s);
    return ();
  }
  /**
    * Is the ID number correct?
    *
    * @param s
    * @return
    */
  public static boolean isIDCode(String s) {
    Matcher m = ID_CODE_PATTERN.matcher(s);
    return ();
  }
  /**
    * Is the encoding correct?
    *
    * @param s
    * @return
    */
  public static boolean isCode(String s) {
    Matcher m = CODE_PATTERN.matcher(s);
    return ();
  }
  /**
    * Is the landline encoding correct?
    *
    * @param s
    * @return
    */
  public static boolean isPhoneNumber(String s) {
    Matcher m = PHONE_NUMBER_PATTERN.matcher(s);
    return ();
  }
  /**
    * Is the postal code correct?
    *
    * @param s
    * @return
    */
  public static boolean isPostCode(String s) {
    Matcher m = POST_CODE_PATTERN.matcher(s);
    return ();
  }
  /**
    * Is the area correct?
    *
    * @param s
    * @return
    */
  public static boolean isArea(String s) {
    Matcher m = AREA_PATTERN.matcher(s);
    return ();
  }
  /**
    * Is the mobile phone number correct?
    *
    * @param s
    * @return
    */
  public static boolean isMobileNumber(String s) {
    Matcher m = MOBILE_NUMBER_PATTERN.matcher(s);
    return ();
  }
  /**
    * Is the bank account correct?
    *
    * @param s
    * @return
    */
  public static boolean isAccountNumber(String s) {
    Matcher m = ACCOUNT_NUMBER_PATTERN.matcher(s);
    return ();
  }
}

PS: Here are two very convenient regular expression tools for your reference:

JavaScript regular expression online testing tool:
http://tools./regex/javascript

Regular expression online generation tool:
http://tools./regex/create_reg

For more information about Android related content, please check out the topic of this site:Android control usage summary》、《Android development introduction and advanced tutorial》、《Android View View Tips Summary》、《Android programming activity operation skills summary》、《Android database operation skills summary"and"Android resource operation skills summary

I hope this article will be helpful to everyone's Android programming design.