2024-05-20 17:12:34 +08:00
|
|
|
|
class RegularExpression {
|
|
|
|
|
|
bool isPhoneNumber(String input) {
|
|
|
|
|
|
// 手机号正则表达式,这里简化为11位数字
|
|
|
|
|
|
final RegExp phoneRegExp = RegExp(r'^\d{11}$');
|
|
|
|
|
|
return phoneRegExp.hasMatch(input);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool isEmail(String input) {
|
|
|
|
|
|
// 邮箱正则表达式,这里简化为常见格式
|
|
|
|
|
|
final RegExp emailRegExp =
|
|
|
|
|
|
RegExp(r'^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$');
|
|
|
|
|
|
return emailRegExp.hasMatch(input);
|
|
|
|
|
|
}
|
2024-06-04 14:44:04 +08:00
|
|
|
|
|
|
|
|
|
|
static RegExp urlRegExp = RegExp(
|
|
|
|
|
|
r'https?:\/\/\S+',
|
|
|
|
|
|
caseSensitive: false,
|
|
|
|
|
|
);
|
2024-09-13 14:50:36 +08:00
|
|
|
|
|
|
|
|
|
|
// 验证登录密码是否至少包含数字、字母、符号中的两种
|
|
|
|
|
|
bool validateString(String value) {
|
|
|
|
|
|
// 正则表达式
|
|
|
|
|
|
RegExp regExpNum = RegExp(r'\d'); // 数字
|
|
|
|
|
|
RegExp regExpLetter = RegExp(r'[a-zA-Z]'); // 字母
|
|
|
|
|
|
RegExp regExpSymbol = RegExp(r'[!@#\$&*~]'); // 符号
|
|
|
|
|
|
|
|
|
|
|
|
// 将字符串与每个正则表达式进行比较
|
|
|
|
|
|
bool hasNum = regExpNum.hasMatch(value);
|
|
|
|
|
|
bool hasLetter = regExpLetter.hasMatch(value);
|
|
|
|
|
|
bool hasSymbol = regExpSymbol.hasMatch(value);
|
|
|
|
|
|
|
|
|
|
|
|
// 计算匹配的数量
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
if (hasNum) count++;
|
|
|
|
|
|
if (hasLetter) count++;
|
|
|
|
|
|
if (hasSymbol) count++;
|
|
|
|
|
|
|
|
|
|
|
|
// 如果数量大于或等于2,返回true
|
|
|
|
|
|
return count >= 2;
|
|
|
|
|
|
}
|
2024-05-20 17:12:34 +08:00
|
|
|
|
}
|