validateUsername static method

String? validateUsername(
  1. String? value, [
  2. bool isProfile = false
])

Validar un nombre de usuario.

  • value: El nombre de usuario ingresado por el usuario.
  • isProfile (opcional, false por defecto): Indica si la validación es para el formulario del perfil. Si es true, el campo puede ser nulo.

Reglas de validación:

  • No estar vacío (excepto en el formulario de perfil).
  • No exceder los 12 caracteres.

Retorna la key del mensaje de error si la validación falla o null si es exitosa.

Implementation

static String? validateUsername(String? value, [bool isProfile = false]) {
  if (!isProfile && (value == null || value.isEmpty)) {
    return 'form_error_required_field';
  } // VALIDAR CAMPOS VACIOS SI NO ES DEL CAMPO DEL PROFILE

  if (value!.length > 12) {
    return "form_error_name_max_length";
  } // SE VALIDA QUE LOS CARACTERES QUE COMPONEN EL NOMRBE DEL USUARIO NO
  // SEA MAYOR DE 12 CARACTERES

  return null;
}