display multiple error

This commit is contained in:
hannathkadher
2024-09-19 13:25:21 +04:00
parent af31d33778
commit 340ac35b3e
2 changed files with 61 additions and 33 deletions
+20 -12
View File
@@ -58,31 +58,39 @@ class AuthCubit extends Cubit<AuthState> {
/////////////////////////////////////VALIDATORS/////////////////////////////////////
String? passwordValidator(String? value) {
List<String> errors = [];
if (value == null || value.isEmpty) {
return "Please enter your password";
errors.add("Please enter your password");
}
if (value.length < 8) {
return 'Password must be at least 8 characters long';
if (value != null && value.length < 8) {
errors.add('Password must be at least 8 characters long');
}
if (!RegExp(r'[a-z]').hasMatch(value)) {
return 'Password must contain at least one lowercase letter';
if (value != null && !RegExp(r'[a-z]').hasMatch(value)) {
errors.add('Password must contain at least one lowercase letter');
}
if (!RegExp(r'[A-Z]').hasMatch(value)) {
return 'Password must contain at least one uppercase letter';
if (value != null && !RegExp(r'[A-Z]').hasMatch(value)) {
errors.add('Password must contain at least one uppercase letter');
}
if (!RegExp(r'\d').hasMatch(value)) {
return 'Password must contain at least one number';
if (value != null && !RegExp(r'\d').hasMatch(value)) {
errors.add('Password must contain at least one number');
}
if (!RegExp(r'[!"#$%&()*+,-./:;<=>?@[\]^_`{|}~]').hasMatch(value)) {
return 'Password must contain at least one special character';
if (value != null &&
!RegExp(r'[!"#$%&()*+,-./:;<=>?@[\]^_`{|}~]').hasMatch(value)) {
errors.add('Password must contain at least one special character');
}
return null;
if (errors.isNotEmpty) {
return errors
.join('\n'); // Join the errors with new lines to show all at once
}
return null; // No errors
}
String? fullNameValidator(String? value) {