validateUsernameOrEmail static method
- String? value
Validar un campo que puede ser un nombre de usuario o un correo electrónico.
value
: El valor ingresado por el usuario.
Si contiene un '@', se valida como correo electrónico. Si no, se verifica que el nombre de usuario no exceda los 12 caracteres.
Retorna la key del un mensaje de error si la validación falla o null
si es exitosa.
Implementation
static String? validateUsernameOrEmail(String? value) {
if (value == null || value.isEmpty) {
return 'form_error_required_field';
} // VALIDAR CAMPOS VACIOS
if (value.contains("@") &&
!RegExp(r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$')
.hasMatch(value)) {
return 'form_error_invalid_email';
} // VALIDAR EL CAMPO DEL EMAIL
if (value.length > 12 && !value.contains("@")) {
return "form_error_name_max_length";
} // SE VALIDA EL NOMBRE, CUADNO NO CONTENGA UN '@' SE VALIDARA QUE NO SEA MAYOR DE 12 CARACTERES
return null;
}