小编给大家分享一下Android开发中正则表达式工具类RegexUtil的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
具体如下:
public class RegexUtil { public static final Pattern PLATE_NUMBER_PATTERN = Pattern .compile("^[\u0391-\uFFE5]{1}[a-zA-Z0-9]{6}$"); public static final Pattern ID_CODE_PATTERN = Pattern .compile("^[a-zA-Z0-9]+$"); public static final Pattern CODE_PATTERN = Pattern .compile("^[a-zA-Z0-9]+$"); public static final Pattern PHONE_NUMBER_PATTERN = Pattern .compile("0\\d{2,3}-[0-9]+"); public static final Pattern POST_CODE_PATTERN = Pattern.compile("\\d{6}"); public static final Pattern AREA_PATTERN = Pattern.compile("\\d*.?\\d*"); public static final Pattern MOBILE_NUMBER_PATTERN = Pattern .compile("\\d{11}"); public static final Pattern ACCOUNT_NUMBER_PATTERN = Pattern .compile("\\d{16,21}"); public static boolean isPlateNumber(String s) { Matcher m = PLATE_NUMBER_PATTERN.matcher(s); return m.matches(); } public static boolean isIDCode(String s) { Matcher m = ID_CODE_PATTERN.matcher(s); return m.matches(); } public static boolean isCode(String s) { Matcher m = CODE_PATTERN.matcher(s); return m.matches(); } public static boolean isPhoneNumber(String s) { Matcher m = PHONE_NUMBER_PATTERN.matcher(s); return m.matches(); } public static boolean isPostCode(String s) { Matcher m = POST_CODE_PATTERN.matcher(s); return m.matches(); } public static boolean isArea(String s) { Matcher m = AREA_PATTERN.matcher(s); return m.matches(); } public static boolean isMobileNumber(String s) { Matcher m = MOBILE_NUMBER_PATTERN.matcher(s); return m.matches(); } public static boolean isAccountNumber(String s) { Matcher m = ACCOUNT_NUMBER_PATTERN.matcher(s); return m.matches(); }}
以上是“Android开发中正则表达式工具类RegexUtil的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网行业资讯频道!