RegexUtils class

正则表达式工具类 提供各种正则表达式验证和处理功能

  • @Author: chuxiong
  • @Created at: 30-07-2025 18:28
  • @Email:
  • description 提供正则表达式相关的工具方法

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

cityMap → Map<String, String>
身份证前两位省份代码字典(懒加载,供 isIDCard18Exact 校验使用)。 改为静态后所有调用共享同一份缓存,行为与原单例一致。
final

Static Methods

getMatches(String regex, String input) → List<String>
Return the list of input matches the regex (all non-overlapping match strings, i.e. group 0 of each match). 返回输入中匹配正则的全部子串列表(非重叠、取整段匹配)。
hasMatch(String? s, Pattern pattern) → bool
判断内容是否符合正则(支持Pattern类型参数)
isAlphabetic(String? s) → bool
验证是否为纯字母
isAlphanumeric(String? s) → bool
验证是否为字母和数字的组合
isApk(String? s) → bool
验证是否为 APK 安装包名(.apk)。
isAudio(String? s) → bool
验证是否为音频文件名(.mp3/.wav/.wma/.amr/.ogg)。
isDate(String input) → bool
Return whether input matches regex of date which pattern is 'yyyy-MM-dd'. 返回输入是否匹配样式为'yyyy-MM-dd'的日期的正则表达式。
isDoc(String? s) → bool
验证是否为 Word 文档名(.doc/.docx)。
isEmail(String input) → bool
Return whether input matches regex of email.
isExcel(String? s) → bool
验证是否为 Excel 表格名(.xls/.xlsx)。
isHexadecimal(String? s) → bool
验证是否为纯十六进制字符串(任意长度 ≥1)。
isHexColor(String? color) → bool
验证十六进制颜色值 (#RGB, #RGBA, #RRGGBB, #RRGGBBAA)
isHtml(String? s) → bool
验证是否为 HTML 文件名(.html,不含 .htm)。
isIDCard(String input) → bool
Return whether input matches regex of id card number. 返回输入是否匹配身份证号码的正则表达式。
isIDCard15(String input) → bool
Return whether input matches regex of id card number which length is 15. 返回输入是否匹配长度为15的身份证号码的正则表达式。
isIDCard18(String input) → bool
Return whether input matches regex of id card number which length is 18. 返回输入是否匹配长度为18的身份证号码的正则表达式。
isIDCard18Exact(String input) → bool
Return whether input matches regex of exact id card number which length is 18. 返回输入是否匹配长度为18的id卡号的正则表达式。
isImage(String? s) → bool
验证是否为图片文件名(.jpeg/.jpg/.gif/.png/.bmp,不区分大小写)。
isInteger(String? s) → bool
验证是否为整数
isIP(String input) → bool
Return whether input matches regex of ip address. 返回输入是否匹配ip地址的正则表达式。
isIPv4(String? ip) → bool
验证IP地址(IPv4)
isIPv6(String? ip) → bool
验证IPv6地址
isJSON(String? str) → bool
验证是否为有效的 JSON 格式。
isMACAddress(String? mac) → bool
验证MAC地址
isMD5(String? s) → bool
验证是否为 MD5 格式(32 位十六进制,大小写均可)。
isMobileExact(String input, {List<String>? newSegments}) → bool
Return whether input matches regex of exact mobile.
isMobileSimple(String input) → bool
Return whether input matches regex of simple mobile. 判断输入字符串是否符合手机号
isNumeric(String? s) → bool
验证是否为纯数字(整数或小数)。
isPdf(String? s) → bool
验证是否为 PDF 文档名(.pdf)。
isPositiveInteger(String? s) → bool
验证是否为正整数
isPostalCode(String? code) → bool
验证邮政编码(中国)
isPpt(String? s) → bool
验证是否为 PPT 演示文稿名(.ppt/.pptx)。
isQQ(String input) → bool
Return whether input matches regex of QQ. 返回是否匹配QQ的正则表达式。
isSHA1(String? s) → bool
验证是否为 SHA-1 格式(40 位十六进制,或冒号分隔 20 字节形态)。
isSHA256(String? s) → bool
验证是否为 SHA-256 格式(64 位十六进制,或冒号分隔 32 字节形态)。
isStrongPassword(String? password) → bool
验证密码强度(至少8位,包含大小写字母、数字和特殊字符)
isTel(String input) → bool
Return whether input matches regex of telephone number. 判断返回输入是否匹配电话号码的正则表达式
isTime(String? time) → bool
验证时间格式 (HH:MM:SS)
isTxt(String? s) → bool
验证是否为文本文件名(.txt)。
isURL(String input) → bool
Return whether input matches regex of url. 返回输入是否匹配url的正则表达式。
isUserName(String input, {String regex = RegexConstants.REGEX_USERNAME}) → bool
Return whether input matches regex of username. 返回输入是否匹配用户名的正则表达式。
isVector(String? s) → bool
验证是否为 SVG 矢量图名(.svg)。
isVideo(String? s) → bool
验证是否为视频文件名(.mp4/.avi/.wmv/.rmvb/.mpg/.mpeg/.3gp)。
isZh(String input) → bool
Return whether input matches regex of Chinese character. 返回输入是否匹配汉字的正则表达式。
matches(String regex, String input) → bool
Return whether input matches the regex. 返回输入是否匹配正则表达式。