Files
social-app/apps/lib/shared/utils/validators.dart
T
qzl 0661016827 feat(auth): transition from email to phone-based OTP authentication
- Replace Email+Password login with Phone+OTP flow
- Remove RegisterCubit and registration screens (email verification)
- Remove ResetPasswordCubit and reset password screens
- Add phone normalization and international dial code support
- Update LoginCubit with sendCode/resend cooldown logic
- Add new widgets: phone prefix selector, confirm sheet
- Update all auth API endpoints: /otp/send, /phone-session
- Update form inputs: Email -> Phone with E.164 validation
- Update tests for new auth flow
2026-03-19 18:42:05 +08:00

42 lines
957 B
Dart

class Validators {
Validators._();
static String? phone(String? value) {
if (value == null || value.isEmpty) {
return '请输入手机号';
}
final phoneRegex = RegExp(r'^\+861[3-9]\d{9}$');
if (!phoneRegex.hasMatch(value)) {
return '请输入有效的 +86 手机号';
}
return null;
}
static String? password(String? value) {
if (value == null || value.isEmpty) {
return '请输入密码';
}
if (value.length < 8) {
return '密码至少需要8位';
}
return null;
}
static String? required(String? value, [String? fieldName]) {
if (value == null || value.isEmpty) {
return '请输入${fieldName ?? '内容'}';
}
return null;
}
static String? nickname(String? value) {
if (value == null || value.isEmpty) {
return '请输入昵称';
}
if (value.length < 2) {
return '昵称至少需要2个字符';
}
return null;
}
}