57 lines
1.7 KiB
Dart
57 lines
1.7 KiB
Dart
import 'package:formz/formz.dart';
|
|
import '../../core/l10n/l10n.dart';
|
|
|
|
class Username extends FormzInput<String, String> {
|
|
const Username.pure() : super.pure('');
|
|
const Username.dirty([super.value = '']) : super.dirty();
|
|
|
|
@override
|
|
String? validator(String value) {
|
|
if (value.isEmpty) return L10n.current.inputUsernameRequired;
|
|
if (value.length < 3) return L10n.current.inputUsernameMin;
|
|
if (value.length > 30) return L10n.current.inputUsernameMax;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
class Phone extends FormzInput<String, String> {
|
|
const Phone.pure() : super.pure('');
|
|
const Phone.dirty([super.value = '']) : super.dirty();
|
|
|
|
static final _regex = RegExp(r'^\d{7,14}$');
|
|
|
|
@override
|
|
String? validator(String value) {
|
|
final normalized = value.replaceAll(RegExp(r'\s+'), '');
|
|
if (normalized.isEmpty) return L10n.current.inputPhoneRequired;
|
|
if (!_regex.hasMatch(normalized)) return L10n.current.inputPhoneInvalid;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
class Password extends FormzInput<String, String> {
|
|
const Password.pure() : super.pure('');
|
|
const Password.dirty([super.value = '']) : super.dirty();
|
|
|
|
@override
|
|
String? validator(String value) {
|
|
if (value.isEmpty) return L10n.current.inputPasswordRequired;
|
|
if (value.length < 6) return L10n.current.inputPasswordMin;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
class VerificationCode extends FormzInput<String, String> {
|
|
const VerificationCode.pure() : super.pure('');
|
|
const VerificationCode.dirty([super.value = '']) : super.dirty();
|
|
|
|
@override
|
|
String? validator(String value) {
|
|
if (value.isEmpty) return L10n.current.inputCodeRequired;
|
|
if (!RegExp(r'^\d{6}$').hasMatch(value)) {
|
|
return L10n.current.inputCodeInvalid;
|
|
}
|
|
return null;
|
|
}
|
|
}
|