validateConfirmPassword static method
Validar la confirmación de la contraseña.
value
: La contraseña de confirmación ingresada.password
: La contraseña original con la que se debe comparar.isProfile
(false
por defecto): Indica si la validación es para el formulario del perfil. Si estrue
, el campo puede ser nulo.
Realiza las mismas validaciones que validatePassword
y, adicionalmente,
verifica que ambas contraseñas coincidan.
Si es para uso del Profile, puede ser nula.
Retorna la key del mensaje de error si la validación falla o null
si es exitosa.
Implementation
static String? validateConfirmPassword(String? value, String? password,
[bool isProfile = false]) {
if (!isProfile && (value == null || value.isEmpty)) {
// SI NO ESTAMOS EN LA PANTALLA DE PERFIL Y EL CAMPO ESTA VACIO, MOSTRAMOS UN MENSAJE
return 'form_error_required_field';
} else {
// SI ESTAMOS EN LA PANTALLA DE PERFIL ENTONCES:
// - SI EL VALUE ES NULO PERO PASSWORD NO LO ES
// - O SI VALUE ESTA VACIO PERO PASSWORD NO LO ESTA
// ENTONCES MOSTRAMOS MENSAJE DE VALIDACION
if ((value == null && password != null) ||
(value!.isEmpty && password!.isNotEmpty)) {
return 'form_error_required_field';
}
} // VALIDAR CAMPOS VACIOS SI NO ES DEL PROFILE
if (value!.isNotEmpty) {
if (value!.length < 8) {
return "form_error_minimum_8_characters";
} // VALIDAR QUE LA CONTRASEÑA CONTENGA AL MENSO 8 CARACTERES
if (value.contains(' ')) {
return "form_error_no_spaces_allowed";
} // VALIDAR QUE LA CONTRASEÑA NO CONTENGA ESPACIOS EN BLANCO
if (!RegExp(r'[!@#$%^&*(),.?":{}|<>]').hasMatch(value)) {
return "form_error_special_character_required";
} // DEBE CONTENER AL MENOS UN CARACTER ESPECIAL
if (!RegExp(r'[0-9]').hasMatch(value)) {
return "form_error_number_required";
} // DEBE CONTENER AL MENOS UN NUMERO
if (value != password) {
return "form_error_passwords_do_not_match";
} // VALIDA QUE LAS CONTRASEÑAS COINCIDAN
} // VALIDAR SI HAY UN VALOR (por el confirmar contraseña del profile)
return null;
}