feat(apps): 重构 UI 架构为 presentation 层并新增 l10n 国际化支持
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import '../l10n/l10n.dart';
|
||||
|
||||
class Validators {
|
||||
Validators._();
|
||||
|
||||
static String? phone(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return L10n.current.validatorPhoneRequired;
|
||||
}
|
||||
final phoneRegex = RegExp(r'^\+861[3-9]\d{9}$');
|
||||
if (!phoneRegex.hasMatch(value)) {
|
||||
return L10n.current.validatorPhoneInvalid86;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static String? password(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return L10n.current.validatorPasswordRequired;
|
||||
}
|
||||
if (value.length < 8) {
|
||||
return L10n.current.validatorPasswordMin8;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static String? required(String? value, [String? fieldName]) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return L10n.current.validatorRequired(
|
||||
fieldName ?? L10n.current.commonUnknown,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static String? nickname(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return L10n.current.validatorNicknameRequired;
|
||||
}
|
||||
if (value.length < 2) {
|
||||
return L10n.current.validatorNicknameMin2;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user